Golang 中三个点...的作用

用法一:

为函数设置不定长度的参数

func myPrint(x ...interface{}) {
	for _, v := range x {
		fmt.Println(v)
	}
}

用法二:

为数组设置默认长度

a := [...]int{12, 32, 12}
// [12 32 12] 3 3 [3]int
fmt.Println(a, len(a), cap(a), reflect.TypeOf(a))

用法三:

append的时候用来打撒slice

a := []int{12, 23}
a = append(a, a...)
posted @   GetcharZp  阅读(95)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示