update slices

master
ZGGSONG 3 years ago
parent bdae343d09
commit 3df2ff4ab8

@ -0,0 +1,30 @@
package main
import "fmt"
func main() {
s := make([]string, 3)
fmt.Println(s)
s[0] = "a"
s[1] = "b"
s[2] = "c"
fmt.Println("set ", s)
fmt.Println("get ", s[2])
// 长度
fmt.Println(len(s), cap(s))
s = append(s, "1")
s = append(s, "4", "5")
fmt.Println("s: ", s)
// 复制
t := make([]string, len(s))
copy(t, s)
fmt.Println("t: ", t)
// 切片 [ : )
l := s[2:]
fmt.Println("l: ", l)
}
Loading…
Cancel
Save