Variadic Functions (Variable Arguments & Spread Operator) - Go Tutorial for Beginners #12
46views
0010:23
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Master variadic functions - accept any number of arguments in Go!
In this lesson, you will learn:
✓ Variadic parameter syntax (...)
✓ How variadic params become slices inside the function
✓ Mixed parameters (regular + variadic)
✓ The spread operator for passing slices
✓ Real-world patterns (logging, min/max)
✓ Why fmt.Println works with any number of arguments
⏱️ Timestamps:
0:00 - Introduction
0:24 - Variadic Basics (sum function)
2:19 - Mixed Parameters
4:16 - Spread Operator
6:27 - Real-World Patterns
9:03 - Recap
9:33 - End
💻 Source Code: https://github.com/GoCelesteAI/go_variadic
📝 Code Highlights:
// Variadic function - accepts any number of ints
func sum(nums ...int) int {
total := 0
for _, n := range nums {
total += n
}
return total
}
// Call with any number of arguments
sum(1, 2, 3, 4, 5)
// Spread a slice into variadic function
numbers := []int{10, 20, 30}
sum(numbers...)
// Mixed parameters (regular + variadic)
func greetAll(greeting string, names ...string) {
for _, name := range names {
fmt.Println(greeting, name)
}
}
// Real-world: append is variadic!
combined := append(slice1, slice2...)
📺 Full Playlist: Go Tutorial for Beginners
📺 Previous: Lesson 11 - Functions
📺 Next: Lesson 13 - Anonymous Functions & Closures
👍 Like and Subscribe for more Go tutorials!
#Go #Golang #Programming #Tutorial #VariadicFunctions #SpreadOperator #LearnToCode
Tags
GoGolangGo tutorialGo for beginnerslearn GoGo programmingvariadic functionsspread operatorvariable argumentsGo functionsprogramming tutorialCelesteAI
Back to tutorialsOpen in YouTube
Duration
10:23
Published
February 1, 2026
Added to Codegiz
March 15, 2026