- // 可变参数用途:收集实参放到1个切片里,len=cap;切片不是要让你修改的,而是让你遍历的
package main
import "fmt"
func fn1(nums ...int) {
fmt.Printf("%T %v %v %v\n", nums, nums, len(nums), cap(nums))
}
func fn2(x, y int, nums ...int) {
fmt.Printf("%d,%d,%T %v %v %v\n", x, y, nums, nums, len(nums), cap(nums))
}
func main() {
// fn1(1, 3, 5, 6)
// fn2() //不行
// fn2(1)//不行
fn2(1, 2) //可以
fn2(3, 4, 5, 6, 7)
}
![](/i/l/?n=23&i=blog/1472910/202301/1472910-20230116003445456-514932065.png)
标签:fn2,nums,变形,fmt,len,int,func,5week
From: https://www.cnblogs.com/john5yang/p/17054542.html