Hello
package main
import "fmt"
func main() {
// 定义一个切片文法
s := []int{1, 2, 3, 4, 5, 6}
printSlice(s)
// 定义一个切片
s1 := s[1:3]
printSlice(s1)
s2 := s[4:]
printSlice(s2)
s3 := s[6:]
printSlice(s3)
s3 = append(s3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
printSlice(s3)
printSlice(s)
}
func printSlice(s []int) { // 参数是一个切片
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
标签:printSlice,s3,s2,fmt,切片,int,测试
From: https://www.cnblogs.com/zshsboke/p/16992721.html