How to Return Multiple Values from a Function in Go

Return multiple values in Go by listing types in the function signature and separating return values with commas.

Go functions return multiple values by listing them in the return type signature and separating them with commas in the return statement.

func divide(a, b int) (int, int, error) {
	if b == 0 {
		return 0, 0, fmt.Errorf("cannot divide by zero")
	}
	return a / b, a % b, nil
}

quotient, remainder, err := divide(10, 3)