Multiple results

A function can return any number of results.

The swap function returns two strings.

multiple-results.go

  1. package main
  2. import "fmt"
  3. func swap(x, y string) (string, string) {
  4. return y, x
  5. }
  6. func main() {
  7. a, b := swap("hello", "world")
  8. fmt.Println(a, b)
  9. }