0% found this document useful (0 votes)
6 views

Go by Example - Multiple Return Values

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Go by Example - Multiple Return Values

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Go by Example: Multiple Return Values https://gobyexample.

com/multiple-return-values

Go by Example: Multiple Return Values


Go has built-in support for multiple return values.
This feature is used often in idiomatic Go, for
example to return both result and error values
from a function.

package main

import "fmt"

The (int, int) in this function signature shows func vals() (int, int) {
that the function returns 2 ints. return 3, 7
}

func main() {

Here we use the 2 different return values from the a, b := vals()


call with multiple assignment. fmt.Println(a)
fmt.Println(b)

If you only want a subset of the returned values, _, c := vals()


use the blank identifier _. fmt.Println(c)
}

$ go run multiple-return-values.go
3
7
7

Accepting a variable number of arguments is


another nice feature of Go functions; we’ll look at
this next.

Next example: Variadic Functions.

by Mark McGranaghan and Eli Bendersky | source | license

1 of 1 11/26/24, 23:34

You might also like