Files
  • main.go
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main

import (
	"fmt"
)

// :show start
func variadic(strs ...string) {
	// strs is a slice of string
	for i, str := range strs {
		fmt.Printf("%d: %s\n", i, str)
	}
	fmt.Print("\n")
}

func main() {
	variadic("Hello", "Goodbye")
	variadic("Str1", "Str2", "Str3")

	// you can also give a slice to a variadic function, with `...`:
	strs := []string{"a", "b"}
	variadic(strs...)
}

// :show end