A function is a named, reusable block of code for doing one job. In Go, you write the input parameters and return type explicitly, which makes it easy to see what a function does at a glance.
go
package main
import "fmt"
func add(x int, y int) int {
return x + y
}
func divide(a int, b int) (int, bool) {
if b == 0 {
return 0, false
}
return a / b, true
}
func main() {
fmt.Println(add(42, 13))
result, ok := divide(10, 2)
fmt.Println(result, ok)
}add function takes two integers and returns one integer. divide returns both a result and a success status at once.
You should see
55 5 trueInfo
Because Go functions can return multiple values, writing a result-plus-error pattern feels natural.