美文网首页
Golang map 与 Python dict 对比

Golang map 与 Python dict 对比

作者: awker | 来源:发表于2018-10-23 23:12 被阅读0次

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 对比

      本文链接:https://www.haomeiwen.com/subject/chvzzftx.html