Go map的range遍历
// MapFunc03 ... map的range遍历 func MapFunc03() { m := make(map[string]string) m["11111"] = "小昆虫" m["22222"] = "小白菜" m["33333"] = "小东风" m["44444"] = "小青蛙" fmt.Println("m=", m) //range遍历map for k, v := range m { fmt.Println("k=", k, "v=", v) } //复杂结构的map m1 := make(map[string]map[string]string) m1["aaaaa"] = make(map[string]string) m1["bbbbb"] = make(map[string]string) m1["aaaaa"]["11111"] = "小昆虫" m1["aaaaa"]["22222"] = "小白菜" m1["bbbbb"]["33333"] = "小东风" m1["bbbbb"]["44444"] = "小青蛙" fmt.Println("m1=", m1) for k1, v1 := range m1 { fmt.Println(k1, v1) for k2, v2 := range v1 { fmt.Println("", k2, v2) } } }
运行结果