0
私はPythonでlist
に新しい要素を追加するように、スライスに新しい要素を追加しようとしましたが、そこにエラー新しい要素をスライスに追加する方法は?
package main
import "fmt"
func main() {
s := []int{2, 3, 5, 7, 11, 13}
printSlice(s)
s[len(s)] = 100
printSlice(s)
}
func printSlice(s []int) {
fmt.Printf("%v\n", s)
}
であり、出力は
[2 3 5 7 11 13]
panic: runtime error: index out of range
どのようにできています私はスライスに新しい要素を追加しますか?
Goでslice
がクローゼットのデータ型がPythonのlist
になっていますか?
ありがとうございました。
https://gobyexample.com/slices – abhink
を/effective_go.html#append)、[Go Language Specification(https://golang.org/ref/spec#Appending_and_copying_slices)]、[Go of Tour(https://tour.golang.org/moretypes/ 7) – JimB
参照:http://stackoverflow.com/questions/20195296/golang-append-an-item-to-a-slice/20197469#20197469 – gavv