标识符与关键字

标识符

在编程语言中标识符就是程序员定义的具有特殊意义的词,比如变量名、常量名、函数名等等。
Go语言中标识符由字母数字和(下划线)组成,并且只能以字母和开头。 举几个例子:abc, _, _123, a123。

关键字

关键字是指编程语言中预先定义好的具有特殊含义的标识符。 关键字和保留字都不建议用作变量名。
Go语言中有25个关键字:

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

预先声明的标识符与关键字 - 图1

此外,Go语言中还有37个 Predeclared identifiers 预先声明的标识符 ¶。

  1. Types:
  2. bool byte complex64 complex128 error float32 float64
  3. int int8 int16 int32 int64 rune string
  4. uint uint8 uint16 uint32 uint64 uintptr
  5. Constants:
  6. true false iota
  7. Zero value:
  8. nil
  9. Functions:
  10. append cap close complex copy delete imag len
  11. make new panic print println real recover

预先声明的标识符与关键字 - 图2