Can you declare multiple variables at once in Go?

前端 未结 6 1246
鱼传尺愫
鱼传尺愫 2020-12-01 15:36

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

6条回答
  •  抹茶落季
    2020-12-01 16:08

    Another way to do this is like this

    var (
       a = 12
       b = 3
       enableFeatureA = false
    
       foo = "bar"
       myvar float64
       anothervar float64 = 2.4
    )
    

    Also works for const

    const (
      xconst    = 5
      boolconst = false
    )
    

提交回复
热议问题