饮歌长啸
有一些提示,这里使用可变参数,例如:sm1 := Sum(1, 2, 3, 4) // = 1 + 2 + 3 + 4 = 10sm2 := Sum(1, 2) // = 1 + 2 = 3sm3 := Sum(7, 1, -2, 0, 18) // = 7 + 1 + -2 + 0 + 18 = 24sm4 := Sum() // = 0func Sum(numbers ...int) int { n := 0 for _,number := range numbers { n += number } return n}或...interface{}任何类型:Ul("apple", 7.2, "BANANA", 5, "cHeRy")func Ul(things ...interface{}) { fmt.Println("<ul>") for _,it := range things { fmt.Printf(" <li>%v</li>\n", it) } fmt.Println("</ul>")}