Golang map 与 Python dict 对比

1、声明类型
golang:counts := make(map[string]int)
// python 不用声明类型
python:counts = {}

2、赋值
golang:counts["age"] = 1
python:counts["age"] = 1

3、遍历
golang:

for key, value := range counts {
   fmt.Println(key, value)
}

python:

for key, value in counts.items():
    print key, value

你可能感兴趣的:(Golang map 与 Python dict 对比)