运行 ❯
获取您
自己
的网站
×
更改方向
更改主题,深色/浅色
转到 Spaces
package main import ("fmt") func main() { a := map[string]int{"one": 1, "two": 2, "three": 3, "four": 4} var b []string // defining the order b = append(b, "one", "two", "three", "four") for k, v := range a { // loop with no order fmt.Printf("%v : %v, ", k, v) } fmt.Println() for _, element := range b { // loop with the defined order fmt.Printf("%v : %v, ", element, a[element]) } }
二:2,三:3,四:4,一:1,
一:1,二:2,三:3,四:4,