Variable naming
1. Capitalization
Observe the following code:
1 func main() { 2 var m int = "你" 3 var M int = "我" 4 fmt.Println(m,M) 5 }
After the execution, no error is reported and the output "you me"
It can be seen that the variable naming in go language is strictly case sensitive
2. Naming rules
2.1 can only start with letters or underscores
2.2 can only contain letters with underscore numbers
2.3 are case sensitive
2.4 cannot use system keywords
2.5 as the name implies-> xxx_xxx xxxXxxx XxxXxx
3. Global code preview
Multiple assignment
1 may be used variable 1, variable 2, 3 ... variable: value = 1, the value 2, 3 ... the value of the format at the same time to a plurality of variable assignment together, the left and right sides of the quantity of data to a peer , or will be error .
1 func main() { 2 a,b,c,d := 1,2,3,4 3 fmt.Println(a,b,c,d) 4 }
If you have unwanted data, you can use "_" to accept it, just throw it in a trash can called "_".
1 func main () { 2 // #Use "_" to discard unnecessary data 3 a, b, _, d: = 1 , " 32sdhas9d238r " , 3 , 4 4 fmt.Println (a, b, d) 5 }
The terminal displays:
2. Global code preview