此代碼位于builti.go:// The append built-in function appends elements to the end of a slice. If// it has sufficient capacity, the destination is resliced to accommodate the// new elements. If it does not, a new underlying array will be allocated.// Append returns the updated slice. It is therefore necessary to store the// result of append, often in the variable holding the slice itself:// slice = append(slice, elem1, elem2)// slice = append(slice, anotherSlice...)// As a special case, it is legal to append a string to a byte slice, like this:// slice = append([]byte("hello "), "world"...)func append(slice []Type, elems ...Type) []Type最后一行讓我感到非常困惑。我不知道是什么意思...Type。這些是其他代碼:package mainimport "fmt"func main() { s := []int{1,2,3,4,5} s1 := s[:2] s2 := s[2:] s3 := append(s1, s2...) fmt.Println(s1, s2, s3)}結果是[1 2] [3 4 5] [1 2 3 4 5]我猜 的功能...是從 中挑選所有元素elems,但我還沒有找到官方解釋。它是什么?
- 1 回答
- 0 關注
- 211 瀏覽
添加回答
舉報
0/150
提交
取消