This is a created article in which the information may have evolved or changed.
1. Variables
1.1 Variable Declaration
The difference between Go and other languages is that the type of the variable is behind the variable name. not: int A, but a int. When a variable is defined, it is assigned a null value of its type by default. This means that after var a int, the value of a is 0. The var s string means that s is assigned a zero-length string, or "".
There are two ways to declare a variable.
The first one uses the VAR keyword to declare a variable, and then assigns a value to the variable.
Func main () {var a int; a = 8;fmt. Println ("Value =" , a);}
The second use: = Complete the Declaration and assignment of the variable at the same time.
Func Main () {a:=8fmt. Println ("Value =" , a);}
Note that the variable declaration must be used later, no compiler error.