源代码:
package main
import (
"fmt"
)
func main() {
arr := [...]int{0, 1, 2}
for i := range arr {
fmt.Println(i, ":", arr, arr[:i], arr[i+1:], "::", append(arr[:i], arr[i+1:]...))
}
fmt.Println("arr :", arr)
}
输出:
0 : [0 1 2] [] [2 2] :: [1 2]
1 : [1 2 2] [1] [2] :: [1 2]
2 : [1 2 2] [1 2] [] :: [1 2]
arr : [1 2 2]
我无法理解为什么“ ar”在“ for”之后和我为1,2时改变了?