下面这段代码很神奇

openset · · 1482 次点击
openset
Less is more!
```go m := map[int]string{ 1: "a", 2: "b", 3: "c", 4: "d", 5: "e", } for k, v := range m { m[k+5] = m[k] + m[k] fmt.Println("k: ", k, "\tv: ", v) } fmt.Println(m) ``` 运行输出结果: ``` k: 1 v: a k: 2 v: b k: 3 v: c k: 4 v: d k: 5 v: e k: 6 v: aa k: 7 v: bb k: 8 v: cc map[10:ee 11:aaaa 12:bbbb 1:a 2:b 6:aa 9:dd 8:cc 13:cccc 3:c 4:d 5:e 7:bb] ```
#4
更多评论
The range expression x is evaluated once before beginning the loop
#2