标签:fun ota example 参数 多个参数 func main += sum
package main
import "fmt"
func main() {
sum(1,2)
sum(1,2,3)
nums := []int{1,2,3,4}
//nums...将nums切片打平为多个参数
sum(nums...)
}
//定义变参函数
func sum(nums ...int) {
fmt.Println(nums," ")
total := 0
for _, num := range nums{
total +=num
}
fmt.Println(total)
}
标签:fun ota example 参数 多个参数 func main += sum
原文地址:https://www.cnblogs.com/promenader/p/9792758.html