The examples in this article describe the use of Go language variable definitions. Share to everyone for your reference. Specifically as follows:
The VAR statement defines a list of variables, the same as the function's argument list, and the type is in the back.
Copy Code code as follows:
Package Main
Import "FMT"
var x, y, Z int
var c, Python, Java bool
Func Main () {
Fmt. Println (x, Y, Z, c, Python, Java)
}
A variable definition can contain an initial value, and each variable corresponds to one.
If the initialization is using an expression, you can omit the type, and the variable obtains the type from the initial value.
Copy Code code as follows:
Package Main
Import "FMT"
var x, y, Z int = 1, 2, 3
var c, Python, Java = True, False, "no!"
Func Main () {
Fmt. Println (x, Y, Z, c, Python, Java)
}
In a function,: = A concise assignment statement can be used instead of the VAR definition where it is explicitly typed.
(: = struct cannot be used outside a function, each block of syntax outside a function must start with a keyword.) )
Copy Code code as follows:
Package Main
Import "FMT"
Func Main () {
var x, y, Z int = 1, 2, 3
C, Python, Java: = True, False, "no!"
Fmt. Println (x, Y, Z, c, Python, Java)
}
I hope this article will help you with your go language program.