How to Return Multiple Values from a Function in Go
A Go function can hand back several results at once: a quotient and a remainder, a value and an error. You list the result types in brackets after the parameters, and the caller receives all of them in one assignment.
Syntax
func <name>(<parameters>) (<type>, <type>) {
return <value>, <value>
}
<a>, <b> := <name>(<arguments>)
| Part | What it does |
|---|---|
(<type>, <type>) | The result types, in order. |
return <value>, <value> | Returns one value per result type. |
<a>, <b> := | Receives the results, in the same order. |
The Go specification on return: "The return value or values may be explicitly listed in the "return" statement. Each expression must be single-valued and assignable to the corresponding element of the function's result type."
The Example
The example divides 17 by 5 and returns both the whole-number result and the remainder.
Prerequisites
- Go.
go runcompiles and runs a single file. This guide uses Go 1.27.4.
Step 1: Write the Function
Create a file named main.go:

package main
import "fmt"
func divide(a, b int) (int, int) {
return a / b, a % b
}
func main() {
quotient, remainder := divide(17, 5)
fmt.Println(quotient, remainder)
}
a / b divides whole numbers and drops the fraction; a % b is what's left over.
Step 2: Run It
go run main.go
3 2

17 divided by 5 is 3, with 2 left over. The command is the same in zsh, bash and PowerShell.
The Most Common Use: a Value and an Error
Many Go functions return a result and an error, such as strconv.Atoi, which returns the number and an error that's nil on success. The caller checks the error before using the value.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Receiving fewer values, as in q := divide(17, 5) | assignment mismatch: 1 variable but divide returns 2 values | Receive both, or use _ for the one you don't need |
| Returning fewer values than the signature lists | not enough return values with have (int) and want (int, int) | Return one value per result type |
| Swapping the order when receiving | The variables get each other's values, with no error if the types match | Keep the same order as the signature |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
assignment mismatch | The number of variables differs from the number of results | Match them, using _ to skip |
declared and not used for one of the results | A result you don't need got a name | Replace that name with _ |
FAQ
Can results have names?
Yes: func divide(a, b int) (quotient, remainder int) names them, and a bare return returns their current values.
Can I pass the results straight to another function?
Yes, when that function takes exactly those parameters: fmt.Println(divide(17, 5)) prints 3 2.
Conclusion
List the result types in brackets, return one value for each, and receive them in the same order with one assignment. Use _ for any result you don't need.
Additional Resources
- Return statements, in the Go specification.
- Effective Go: multiple return values.
