Functions
A function is a reusable block of code.
Think of it as a recipe you can call again and again.
You declare it with func.
You list inputs with names and types. You may return a result.
Declaring and calling
Write func, a name, parentheses, then braces.
Call it by writing the name and passing values.
Parameters and return types
Parameter types come after names.
If several parameters share a type, write the type once at the end of the group.
Put the return type after the parentheses.
Named return values
You can name return parameters. A bare return then sends those named values back.
That can make longer functions easier to follow.
Variadic parameters
A parameter like nums ...int accepts zero or more ints.
Inside the function it becomes a stretchy list.
Why functions help
Functions stop copy-paste.
Name them after what they do.
Small recipes are easier to test and reuse.
Next lesson: Go's big idea of returning more than one value.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.