- Variable
- Use the keyword var to define the variable and automatically initialize it to a value of 0. If you provide an initialization value, you can omit the variable type, which is automatically inferred by the compiler.
- You can define a variable inside a function by using the : = method
Func Main () {x:}
- Multiple variables can be defined at once
" ABC ", 123var (a intb float32) func main () {n, S:"Hello, world! " println (x, S, N)}
- _ is used to ignore the value, the placeholder.
- The compiler uses unused local variables as errors
- Constant
- The constant value must be a number, string, and Boolean value that can be determined by the compilation period.
const x, y int = 1, 2//"Hello, world! " ////= ten,= false"xxx" // No compilation errors are raised with local constants. }
- In a constant group, if the type and initialization values are not provided, it is treated the same as the previous constant.
- The constant value can also be Len, cap, unsafe. The function return value of the result can be determined by the compile period such as Sizeof
- Enumeration
- The IOTA keyword defines the self-increment enumeration value in a constant group that starts at 0 by the row count.
= Iota////1//2//3//4//5//6)
- If Iota is interrupted, it must be explicitly restored.
= Iota////1"C" // CD //= Iota//4 //5)
- Basic type
Go Language basic type (1)