Multiple Variable Declarations in Go
Go provides a way to declare multiple variables at once, simplifying code and improving efficiency.
Inline Assignment:
To declare multiple variables and assign them values inline, use the following syntax:
a, b, c := 80, 80, 80
This statement declares three variables (a, b, and c) and assigns each the value 80.
Type Declaration:
To declare multiple variables without assigning values, use the var keyword:
var a, b, c string
This statement declares three variables (a, b, and c) as strings without assigning any values.
Example:
The following code demonstrates multiple variable declarations:
package main import "fmt" func main() { // Inline assignment a, b, c := 80, 80, 80 // Type declaration var x, y, z string x = "foo" fmt.Println(a, b, c, x) }
Output:
80 80 80 foo
The above is the detailed content of How Can I Declare Multiple Variables in Go?. For more information, please follow other related articles on the PHP Chinese website!