Go语言之标识符与关键字

时间:2021-08-22 15:17:16   收藏:0   阅读:27

一、标识符

Go中对各种变量、函数等命名时使用的字符序列称为标识符。

(一)标识符的命名规则

下面的案例均是错误的使用:

ab-c  //不能以运算符“-”作为标识符
ab c //不能以空格作为标识符
_ //不能以“_”作为标识符

...

(二)注意事项

如下:

技术分享图片

 在main.go文件中引用test包中的变量,引用方法是包名.变量名:

技术分享图片

 然后执行main.go文件,如果出现类似 main.go:5:2: package go_tutorial/day03/identifier/test is not in GOROOT (D:\go\src\go_tutorial\day03\identifier\test) 这种错误,设置以下如下参数:

go env -w GO111MODULE=off

二、关键字

Go中有保留关键字25个,详情如下表:

break  default  func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var

三、系统预定义标识符

预定义标识符就是事先定义好的有特殊意义的词,与关键字类似。

append bool byte cap close complex complex64 complex128 uint16
copy false float32 float64 imag int int8 int16 uint32
int32 int64 iota len make new nil panic uint64
print println real recover string true uint uint8 uintptr

原文:https://www.cnblogs.com/shenjianping/p/15171698.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!