package main import( "fmt" ) func main(){ var yk = make(map[string][]string) yk["one"] = []string{"a123", "a456", "a789"} fmt.Println("yk[one] len = ", len(yk["one"])) i := len(yk["one"]) for j:=0; j<i; j++{ fmt.Println(yk["one"][j]) } yk["two"] = []string{"b123", "b456"} for k,v := range yk{ fmt.Println("key:", k) fmt.Println("values:", v) for _, vs := range v { fmt.Println("value:", vs) } } }
结果
yk[one] len = 3
a123
a456
a789
key: two
values: [b123 b456]
value: b123
value: b456
key: one
values: [a123 a456 a789]
value: a123
value: a456
value: a789
有疑问加站长微信联系(非本文作者)