Home >Backend Development >Golang >How Can I Declare Multiple Variables with the Same Value in Go?
Declaring Multiple Variables Simultaneously in Golang
In Python, you can succinctly declare multiple variables and assign them the same value. For instance, you can execute the following code to set three variables to 80:
a = b = c = 80
Can you perform a similar operation in Golang?
Answer:
Yes, you can declare and assign values to multiple variables simultaneously in Golang.
Method 1: Using the var Keyword:
var a, b, c string a = "foo" fmt.Println(a)
Method 2: Inline Assignment:
While not as convenient as in Python, Golang allows for inline variable declaration and assignment:
a, b, c := 80, 80, 80
The above is the detailed content of How Can I Declare Multiple Variables with the Same Value in Go?. For more information, please follow other related articles on the PHP Chinese website!