阿里巴巴|golang2021数据类型(1)Golang内置类型和函数

1. Golang内置类型和函数
1.1. 内置类型
1.1.1. 值类型:
bool
int(32 or 64) int8 int16 int32 int64
uint(32 or 64) uint8(byte) uint16 uint32 uint64
float32 float64
string
complex64 complex128
array -- 固定长度的数组
1.1.2. 引用类型:(指针类型)
slice -- 序列数组(最常用)
map -- 映射
chan -- 管道
1.2. 内置函数
Go 语言拥有一些不需要进行导入操作就可以使用的内置函数 。 它们有时可以针对不同的类型进行操作 , 例如:len、cap 和 append , 或必须用于系统级的操作 , 例如:panic 。 因此 , 它们需要直接获得编译器的支持 。
append -- 用来追加元素到数组、slice中返回修改后的数组、slice
close -- 主要用来关闭channel
delete -- 从map中删除key对应的value
panic -- 停止常规的goroutine (panic和recover:用来做错误处理)
recover -- 允许程序定义goroutine的panic动作
real -- 返回complex的实部 (complex、real imag:用于创建和操作复数)
imag -- 返回complex的虚部
make -- 用来分配内存 , 返回Type本身(只能应用于slice map channel)
new -- 用来分配内存 , 主要用来分配值类型 , 比如int、struct 。 返回指向Type的指针
cap -- capacity是容量的意思 , 用于返回某个类型的最大容量(只能用于切片和 map)
copy -- 用于复制和连接slice , 返回复制的数目
len -- 来求长度 , 比如string、array、slice、map、channel, 返回长度
print、println -- 底层打印函数 , 在部署环境中建议使用 fmt 包
1.3. 内置接口error
type error interface { //只要实现了Error()函数 , 返回值为String的都实现了err接口
【阿里巴巴|golang2021数据类型(1)Golang内置类型和函数】Error() String
Golang 更明确的数字类型命名 , 支持 Unicode , 支持常用数据结构 。
| 类型 | 长度(字节) | 默认值 | 说明 |
| bool | 1 | false | |
| byte | 1 | 0 | uint8 |
| rune | 4 | 0 | Unicode Code Point int32 |
| int uint | 4或8 | 0 | 32 或 64 位 |
| int8 uint8 | 1 | 0 | -128 ~ 127 0 ~ 255 , byte是uint8 的别名
|
