このコードは次の場所にあり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 main
import "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
だと思いますが、公式の説明は見つかりませんでした。それは何ですか?
builtin.goのコードはドキュメントとして機能します。コードはコンパイルされません。
...
関数の最後のパラメータは、可変長引数であることを指定します。Variadic関数はGo言語仕様に記載されています。つまり、可変パラメータ関数は、最後のパラメータに任意の数の引数を指定して呼び出すことができます。
タイプの一部は、任意の囲碁タイプのスタンドです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加