定义map var m map[string]int //定义map
初始化map m = make(map[string]int) //初始化map
修改map中ok 的值 m["ok"] =123
删除元素 delete(m, "Answer") 删除key=Answer的元素
------------------------------------------------------------
package main
import "fmt"
func main() {
var m map[string]int //定义map
m = make(map[string]int) //初始化map
m["name"] = 99 //赋值
fmt.Println(m)
var k = map[string]int{
"a": 1,
"ab": 112,
"age": 65,
}
fmt.Println(k)
}
------------------------------------------------------------
package main
import "fmt"
func main() {
var m map[string]int //定义map
m = make(map[string]int) //初始化map
m["name"] = 99 //赋值
fmt.Println(m)
var k = map[string]int{
"a": 1,
"ab": 112,
"age": 65,
}
fmt.Println(k)
fmt.Println("------------------")
v, ok := k["age"]
fmt.Println(v, ok)
//无法取出age1的值
v1, ok1 := k["age1"]
fmt.Println(v1, ok1)
}
------------------------------------------------------------
go语言开发交流qq群 857263711
保持进步
希望每个人都能找到自己喜欢的方式生活、工作。