package main
import "fmt"
func main() {
//创建一个空的slices
s := make([]string, 3)
fmt.Println("emp", s)
//slice赋值
s[0] = "a"
s[1] = "b"
s[2] = "c"
fmt.Println("set:", s)
fmt.Println("get:", s[2])
//slice长度
fmt.Println("len", len(s))
//slice append添加数值
s = append(s, "d")
s = append(s, "e", "f")
fmt.Println("apd:", s)
//切片复制 s复制到c
c := make([]string, len(s))
copy(c, s)
fmt.Println("cpy", c)
//获取切片的部分元素
l := s[2:5]
fmt.Println("sl1:", l)
//切分到s[:5]
l = s[:5]
fmt.Println("sl2", l)
//从s[2:]切分
l = s[2:]
fmt.Println("sl3", l)
//切片t赋值
t := []string{"g", "h", "i"}
fmt.Println("dcl", t)
//二维切片
twoD := make([][]int, 3)
for i := 0; i <</span> 3; i++ {
innerLen := i + 1
twoD[i] = make([]int, innerLen)
for j := 0; j <</span> innerLen; j++ {
twoD[i][j] = i + j
}
}
fmt.Println("2d:", twoD)
}