You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
411 B
31 lines
411 B
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)
|
|
}
|