package main
import "fmt"
func main(){
sample := map[string]string{
"key1":"value1",
"key2":"value2",
"key3":"value3",
}
for i := 0;i<3;i++{
fmt.Println(sample)
}
}
上述Go代码只打印一张地图[字符串]字符串三次。
我期待它一个固定的输出,但它显示为以下几点:
map[key3:value3 key2:value2 key1:value1]
map[key1:value1 key3:value3 key2:value2]
map[key2:value2 key1:value1 key3:value3]
它改变!
而在蟒蛇:
#!/bin/env python
#encoding=utf8
sample = {
"key1":"value1",
"key2":"value2",
"key3":"value3",
}
for i in range(3):
print sample
输出:
{'key3': 'value3', 'key2': 'value2', 'key1': 'value1'}
{'key3': 'value3', 'key2': 'value2', 'key1': 'value1'}
{'key3': 'value3', 'key2': 'value2', 'key1': 'value1'}`