Go语言 遍历map中的键值对
map 的遍历过程使用 for range 循环完成,代码如下:
package main import "fmt" func main() { mapNum := make(map[string]int) mapNum["key1"] = 1 mapNum["key2"] = 2 mapNum["key3"] = 3 mapNum["key4"] = 4 //输出map集合key和value for k, v := range mapNum { fmt.Printf("key:%s value:%d \n", k, v) } //只输出value for _, v := range mapNum { fmt.Printf(" value:%d \n", v) } //只输出key for k := range mapNum { fmt.Printf("key:%s \n", k) } }
相关推荐
小科的奋斗 2020-11-16
wfs 2020-10-29
哈嘿Blog 2020-10-26
bearhoopIT之道 2020-11-11
文山羊 2020-11-07
jaminliu0 2020-10-25
railssky 2020-10-25
小科的奋斗 2020-10-24
HELLOBOY 2020-10-23
牧 2020-10-22
狼窝 2020-10-22
ciqingloveless 2020-10-15
专注前端开发 2020-10-12
哈嘿Blog 2020-09-08
linmufeng 2020-09-08
qidiantianxia 2020-09-15
哈嘿Blog 2020-08-16