## 一、 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 | |
## 二、Go 语言的 36 个预定义标识符
| 标识符 | 说明 |
| --- | --- |
| 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 | |
## 三、格式化符号
| 格 式 | 描 述 |
| --- | --- |
| %v | 按值的本来值输出 |
| %+v | 在 %v 基础上,对结构体字段名和值进行展开 |
| %#v | 输出 Go 语言语法格式的值 |
| %T | 输出 Go 语言语法格式的类型和值 |
| %% | 输出 % 本体 |
| %b | 整型以二进制方式显示 |
| %o | 整型以八进制方式显示 |
| %d | 整型以十进制方式显示 |
| %x | 整型以十六进制方式显示 |
| %X | 整型以十六进制、字母大写方式显示 |
| %U | Unicode 字符 |
| %f | 浮点数 |
| %p | 指针,十六进制方式显示 |
#### 实例
~~~
package main
import (
"fmt"
"os"
)
type point struct {
x, y int
}
func main() {
p := point{1, 2}
fmt.Printf("%v\n", p)
fmt.Printf("%+v\n", p)
fmt.Printf("%#v\n", p)
fmt.Printf("%T\n", p)
fmt.Printf("%t\n", true)
fmt.Printf("%d\n", 123)
fmt.Printf("%b\n", 14)
fmt.Printf("%c\n", 33)
fmt.Printf("%x\n", 456)
fmt.Printf("%f\n", 78.9)
fmt.Printf("%e\n", 123400000.0)
fmt.Printf("%E\n", 123400000.0)
fmt.Printf("%s\n", "\"string\"")
fmt.Printf("%q\n", "\"string\"")
fmt.Printf("%x\n", "hex this")
fmt.Printf("%p\n", &p)
fmt.Printf("|%6d|%6d|\n", 12, 345)
fmt.Printf("|%6.2f|%6.2f|\n", 1.2, 3.45)
fmt.Printf("|%-6.2f|%-6.2f|\n", 1.2, 3.45)
fmt.Printf("|%6s|%6s|\n", "foo", "b")
fmt.Printf("|%-6s|%-6s|\n", "foo", "b")
s := fmt.Sprintf("a %s", "string")
fmt.Println(s)
fmt.Fprintf(os.Stderr, "an %s\n", "error")
}
~~~
执行结果:
```
{1 2}
{x:1 y:2}
main.point{x:1, y:2}
main.point
true
123
1110
!
1c8
78.900000
1.234000e+08
1.234000E+08
"string"
"\"string\""
6865782074686973
0xc0000aa070
| 12| 345|
| 1.20| 3.45|
|1.20 |3.45 |
| foo| b|
|foo |b |
a string
an error
```