package main import "fmt" func main() { nums := []int {1, 2, 3, 5, 4} sum := 0 for _, num := range nums{ //fmt.Println(num) sum += num } fmt.Println(sum) fmt.Println(mysum(1,2,3)) fmt.Println(mysum(1,2,3,4)) } // 可变参数函数 func mysum(nums ...int) int { total := 0 for _, num := range nums{ total += num } return total }