1、布尔型
bool,值为true(真)或false(假)。
2、整数型
int8 有符号 8 位整型 (-128 到 127) 长度:8bit
int16 有符号 16 位整型 (-32768 到 32767)
int32 有符号 32 位整型 (-2147483648 到 2147483647)
int64 有符号 64 位整型 (-9223372036854775808 到 9223372036854775807)
uint8 无符号 8 位整型 (0 到 255) 8位都用于表示数值:
uint16 无符号 16 位整型 (0 到 65535)
uint32 无符号 32 位整型 (0 到 4294967295)
uint64 无符号 64 位整型 (0 到 18446744073709551615)
int 、uint 根据底层平台,表示32或64位整数。
uintptr 无符号整型,用于存放一个指针
3、浮点型
float32 32位浮点型数
float64 64位浮点型数
complex64 32 位实数和虚数
complex128 64 位实数和虚数
4、字符型
byte 单个字符,类似于uint8
5、字符串类型
string 字符串
6、rune类型
类似 int32 (Go语言的字符串的字节使用UTF-8编码标识Unicode文本,中文字符不是占用2个自己而是占用3个字节,rune用于获取真实的字节占用数)
使用方法如下:
str := "hello 世界" //方法一 fmt.Println("RuneCountInString:", utf8.RuneCountInString(str)) //方法二 fmt.Println("rune:", len([]rune(str)))
7、补充:
7.1 Go语言中的关键字(25个,均为小写)
break、default、func、interface、select、case、defer、go、map、struct、chan、else、goto、package、switc、const、fallthrough、if、range、type、continue、for、import、return、var
7.2 30多个预定义名字
7.2.1 内建常量
true、false、iota、nil
7.2.2 内建类型
int、int8、int16、int32、int64、uintptr、float32、float64、complex64、complex128、bool、byte、rune、string、error
7.2.3 内建函数
make、len、cap、new、append、copy、close、delete、complex、real、image、panic、recover