HiveBrain v1.2.0
Get Started
← Back to all entries
patterngoCritical

Can you declare multiple variables at once in Go?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
variablesyouoncedeclaremultiplecan

Problem

Is it possible to declare multiple variables at once using Golang?

For example in Python you can type this:

a = b = c = 80


and all values will be 80.

Solution

Yes, you can:

var a, b, c string
a = "foo"
fmt.Println(a)


You can do something sort of similar for inline assignment, but not quite as convenient:

a, b, c := 80, 80, 80

Code Snippets

var a, b, c string
a = "foo"
fmt.Println(a)
a, b, c := 80, 80, 80

Context

Stack Overflow Q#21071507, score: 146

Revisions (0)

No revisions yet.