Golang's grammatical sugar
...
There are three points in the Go language function ...
represented as mutable parameters, which is the icing syntax of go, which means that you can accept any number of parameters of the same type.
func print(values...string) { //可以接受任意个string参数 for _, v:= range values{ fmt.Println("---> ",v) }}func main(){ values := []string{"abc", "def", "hig", "klm",} print(values...) }
:=
:=
Is the assignment of go and declarative syntax sugar, its function is declaration, assignment and type inference.
//第一种方法var number1 number2 number3 intnumber1, number2, number3 = 1, 2, 3 //第二种方法var number1, number2, number3 = 1, 2, 3 //第三种方法number1, number2, number3 := 1, 2, 3
:=
Can be used only if there are undefined variables on the left (variables that are defined can also)
:=
Only semantic checks, loops can also be used, the first time after the effect and = the same
:=
and = both require that the left and right values correspond to the variable one by one and do not truncate
- Special case, Map, Chan, type presumption can return a value, or it can be two values
- Always returns a value of 0 and False if the key does not exist in map, otherwise the latter returns true
- When Chan closes, it always returns a value of 0 and False, otherwise the latter returns true