Go声明int类型的slice有一种很随意的方式,第一次见到这样的写法:
package main import "fmt" func main() { s := []int{0, 1, 2, 3, 8: 100} fmt.Println(s, len(s1, cap(s)) }
运行结果:
[0 1 2 3 0 0 0 0 100] 9 9