| 基本数据类型 |
| :-- |
| bool |
| string |
| int int8 int16 int32 int64 |
| uint uint8 uint16 uint32 uint64 uintptr |
| byte // alias for uint8 |
| rune // alias for int32,represents a Unicode code point |
| float32 float64 |
| complex64 complex128 |
布尔类型
var v1 bool //默认值为false
v1 = true
v2 := (1 == 2) // v2也会被推导为bool类型
数值类型
整型:
int8、byte、int16、int、uint、uintptr等。
| 类型 | 长度(字节) | 取值范围 |
| — | — | — |
| int8 | 1 | -128 ~ 127 |
| uint8(即byte) | 1 | 0 ~ 255 |
| int16 | 2 | -32 768 ~ 32 767 |
| uint16 | 2 | 0 ~ 65 535 |
| int32 | 4 | -2 147 483 648 ~ 2 147 483 647 |
| uint32 | 4 | 0 ~ 4 294 967 295 |
| int64 | 8 | -9 223 372 036