在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
定义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 保持进步 |
请发表评论