// Created on savesnippets.com ยท https://savesnippets.com/nQkwtaCLTefhMa package main import "fmt" func sum(nums ...int) int { total := 0 for _, n := range nums { total += n } return total } func greet(prefix string, names ...string) { for _, n := range names { fmt.Println(prefix, n) } } func main() { fmt.Println(sum()) // 0 fmt.Println(sum(1, 2, 3, 4, 5)) // 15 // Spread a slice into variadic args nums := []int{10, 20, 30} fmt.Println(sum(nums...)) // 60 greet("Hello,", "Alice", "Bob", "Cara") // Hello, Alice // Hello, Bob // Hello, Cara }