Functions and Methods
Multiple Return Values
Go functions can return more than one value.
Multiple Return Values
multi_return.go
package main
import "fmt"
func divide(total int, parts int) (int, int) {
quotient := total / parts
remainder := total % parts
return quotient, remainder
}
func main() {
var total =
quotient, remainder := divide(total, 5)
fmt.Println("total=", total)
fmt.Println("quotient=", quotient)
fmt.Println("remainder=", remainder)
}
package main
import "fmt"
func divide(total int, parts int) (int, int) {
quotient := total / parts
remainder := total % parts
return quotient, remainder
}
func main() {
var total =
quotient, remainder := divide(total, 5)
fmt.Println("total=", total)
fmt.Println("quotient=", quotient)
fmt.Println("remainder=", remainder)
}
package main
import "fmt"
func divide(total int, parts int) (int, int) {
quotient := total / parts
remainder := total % parts
return quotient, remainder
}
func main() {
var total =
quotient, remainder := divide(total, 5)
fmt.Println("total=", total)
fmt.Println("quotient=", quotient)
fmt.Println("remainder=", remainder)
}
multiple return
A function signature can list several return types, and callers assign each returned value.