January 2018
Intermediate to advanced
340 pages
8h 6m
English
Functions are defined with the func keyword. Functions can have multiple parameters. All parameters are positional and there are no named parameters. Go supports variadic parameters allowing for an unknown number of parameters. Functions are first-class citizens in Go, and can be used anonymously and returned as a variable. Go also supports multiple return values from a function. The underscore can be used to ignore a return variable.
All of these examples are demonstrated in the following code source:
package mainimport "fmt"// Function with no parametersfunc sayHello() { fmt.Println("Hello.")}// Function with one parameterfunc greet(name string) { fmt.Printf("Hello, %s.\n", name)}// Function with multiple params of same typefunc ...Read now
Unlock full access