Function Basics and Signatures
Parameters, return types, and calling conventions
Defining a Function
In Go, functions are defined with the func keyword:
func greet(name string) string {
return "Hello, " + name
}Parameters and Arguments
Parameters are typed and listed as name type pairs. Multiple parameters of the same type can share the type annotation:
func add(x, y int) int {
return x + y
}
func rect(w, h float64) float64 {
return w * h
}All lessons in this course
- Function Basics and Signatures
- Multiple Return Values
- Variadic Functions
- defer, Anonymous Functions & Closures