【发布时间】:2013-06-30 22:01:22
【问题描述】:
您可以在 Go Playground 上run the example code。
代码如下:
package main
import "fmt"
func main() {
numbers := []int{1, 2, 3, 4, 5}
fmt.Println(numbers)
_ = append(numbers[0:1], numbers[2:]...)
fmt.Println(numbers)
}
输出:
[1 2 3 4 5]
[1 3 4 5 5]
为什么 numbers 切片被 append 修改了?这是预期的行为吗?如果是,你能向我解释为什么吗?我以为append 不会修改它的论点。
【问题讨论】:
-
您是否阅读了附件中的documentation?我认为它很好地解释了这种行为。
标签: go