Skip to content
Justice Tech School

Functions

func name(params) result. Multiple return values are common. Parameters of the same type can share one type.

Example
package main

import "fmt"

func add(a, b int) int { return a + b }
func divmod(a, b int) (int, int) { return a / b, a % b }

func main() {
	q, r := divmod(7, 2)
	fmt.Println(q, r, add(1, 2))
}

Result

3 1 3

Exercise

Return two values.

func f() (int, )

Quiz Test

Can Go functions return several values?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.