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)
Go lets a function send back several pieces of information at once instead of just one. You list the types you want to return in the function definition and separate the actual values with commas when you return them. Think of it like a delivery driver handing you a package, a receipt, and a map all at the same time.