Defines a function.
Syntax
func name(p type) returnType { }Description
Parameter type comes AFTER the name. Return type is specified after the parentheses.
Example
package main
import "fmt"
func square(x int) int {
return x * x
}
func main() {
fmt.Println(square(5))
}Expected output
25
When to use?
Preventing code repetition.