遍历key
package main
import (
"fmt"
)
func main() {
var mymap map[string]string
mymap = map[string]string{"1a": "Very","2b": "good","3c": "day"}
for one := range mymap {
fmt.Println(one)
}
}
output:
1a
2b
3c
遍历value
package main
import (
"fmt"
)
func main() {
var mymap map[string]string
mymap = map[string]string{"1a": "Very","3c": "day"}
for _,value := range mymap {
fmt.Println(value)
}
}
output:
Very
good
day
遍历key-value
package main
import (
"fmt"
)
func main() {
var mymap map[string]string
mymap = map[string]string{"1a": "Very","3c": "day"}
for key,value := range mymap {
fmt.Println(key,":",value)
}
}
output:
原文链接:https://www.f2er.com/go/187880.html3c : day 1a : Very 2b : good