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 |
println | real | recover | string | true | uint | uint8 | uintptr |
原文:https://www.cnblogs.com/shenjianping/p/15171698.html