GO不一致的声明

huangapple go评论71阅读模式
英文:

GO inconsistent declaration

问题

我是你的中文翻译助手,下面是翻译好的内容:

我是一个GO的新手,刚开始学习这门语言。
为什么这个是正确的:

const name, age = "Kim", 22

但这个是错误的:

const name, age := "Kim", 22

英文:

I'm a noob at GO, Just starting to learn the language.
why is this fine:

const name, age = "Kim", 22

but this is not

const name, age := "Kim", 22

答案1

得分: 5

A Tour of Go

> 常量不能使用:=语法声明。

:=用于声明一个变量,并从值中推断其类型。然而,声明和初始化变量与声明常量是不同的。请参阅这里这里

英文:

From A Tour of Go:

> Constants cannot be declared using the := syntax.

:= is used to declare a variable inferring its type from the value. Though, declaring and initializing a variable is not the same as declaring a constant. See also here and here.

huangapple
  • 本文由 发表于 2022年6月13日 06:41:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/72596375.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定