test := make(map[int]string)
test := map[int]string{
1: "a",
2: "b",
3: "c",
}
map 的所有 key 要同型別,所有的value 也要同型別
package main
import (
"fmt"
)
func main() {
test := map[string]int{
"jason": 12,
"eason": 15,
}
for idx := range test {
fmt.Println(test[idx])
}
}
package main
import (
"fmt"
)
func main() {
var test = map[string]map[string]int{
"a": map[string]int{}, // 記得要逗點
}
test["a"]["w"] = 123
fmt.Println(test)
}