你可以在Go中一次声明多个变量吗? [英] Can you declare multiple variables at once in Go?

查看:1290
本文介绍了你可以在Go中一次声明多个变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Golang一次声明多个变量?

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

例如在Python中,您可以输入以下内容:

For example in Python you can type this:

a = b = c = 80

和所有值都是80.

推荐答案

是的,您可以:

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

这篇关于你可以在Go中一次声明多个变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆