Skip to content

Commit

Permalink
Merge pull request #33 from tsingbx/main
Browse files Browse the repository at this point in the history
Add help doc for multiple return values
  • Loading branch information
xushiwei authored Oct 9, 2023
2 parents f562ff2 + c603ea6 commit a8b7e9d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 202-Multiple-Return-Values/multi-rets.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

import "fmt"

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

// Here we use the 2 different return values from the
// call with _multiple assignment_.
a, b := vals()
println a
println b

// If you only want a subset of the returned values,
// use the blank identifier `_`.
_, c := vals()
println c

0 comments on commit a8b7e9d

Please sign in to comment.