package main
import "fmt"
func main() {
// create a slice from an array
x := [3]string{"A", "B", "С"}
s := x[:] // a slice referencing the storage of x
// x[1] = "O"
t := append(s, "D") // append items to slice s
x[1] = "O"
fmt.Println("%+v", x)
fmt.Println("%+v", s)
fmt.Println("%+v", t)
}
https://go.dev/play/p/g-eGRJLteAH
t 为什么是 [A B С D]
我的理解是 t 在 s 的基础上加了个‘D' , x 改了 s, t 也要跟着变啊.