1、创建映射
映射类似于java中的map,同样需要声明键值对,例如
var players = make(map[string]int)
解释:与创建切片一致同样需要使用make函数,map[string]声明了键为string类型,int声明了值为int类型
2、给映射赋值
players["test"] = 1
players["test2"] = 2
players["test3"] = 3
3、获取值
fmt.Println(players["test"])
fmt.Println(players)
解释:获取键为test的值,获取players变量中所有的映射值
4、删除值
delete(players, "test")
解释:删除players变量中键为test的值
1879

被折叠的 条评论
为什么被折叠?



