饮歌长啸

有一些提示,这里使用可变参数,例如: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 {&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; n := 0&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; for _,number := range numbers {&nbsp; &nbsp; &nbsp; &nbsp; n += number&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return n}或...interface{}任何类型:Ul("apple", 7.2, "BANANA", 5, "cHeRy")func Ul(things ...interface{}) {&nbsp; fmt.Println("<ul>")&nbsp; &nbsp;&nbsp;&nbsp; for _,it := range things {&nbsp; &nbsp; fmt.Printf("&nbsp; &nbsp; <li>%v</li>\n", it)&nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; fmt.Println("</ul>")}
0 0