Go 语言中 Map 的遍历 - 使用 for 循环
//{/'title/':/'Go 语言中 Map 的遍历 - 使用 for 循环/',/'description/':/'本文介绍了如何使用 for 循环遍历 Go 语言中的 Map。我们将展示如何获取 Map 中的键值对并进行迭代。/',/'keywords/':/'Go, map, 遍历, for循环, 键值对, 迭代/',/'content/':/'可以使用 for 循环来遍历一个 map。在每次迭代中,可以使用两个变量来获取 map 中的键和值。//n//n例如://n//ngo//npackage main//n//nimport ///'fmt///'//n//nfunc main() {//n m := map[string]int{/'a/': 1, /'b/': 2, /'c/': 3}//n//n // 遍历map//n for key, value := range m {//n fmt.Println(key, value)//n }//n}//n//n//n输出://n//n//na 1//nb 2//nc 3//n//n//n在每次迭代中,key变量将获取 map 中的键,value变量将获取 map 中与该键关联的值。//n//n/
原文地址: https://www.cveoy.top/t/topic/qbMx 著作权归作者所有。请勿转载和采集!