理解:=||nil||defer in Go

  • := vs. =

    They are both assignments in Go.

    // =
    var name type = expression
    var x int = 1
    // :=   short variable declaration
    name := expression // the type of name is determined by the type of expression
    

    := is a declaration, whereas = is an assignment.

  • var

    The var statement declares a list of variables; as in function argument lists, the type is last.

    A var statement can be at package or function level.

  • nil

  • defer

  • References

  1. What is the difference between := and = in Go?

猜你喜欢

转载自blog.csdn.net/The_Time_Runner/article/details/108893370
今日推荐