Ad space (banner)
๐ŸนGo Lessons
Lesson 47 / 68

Functions That Return Multiple Values

In this lesson you will learn how to return several values from a Go function, so you are not limited to a single return value. This is for anyone searching for "Go multiple return values how to use".

A Go function returns several values simply by declaring several return types, as in (int, int). Picture handing over one box containing two cards, a name and a score.

The sample code has minMax() declare the two return types (int, int) and hand back both with return min, max. The caller receives them together with min, max := minMax(...).

A common stumbling block for beginners is seeing how this connects to error handling. The value, err := someFunc() form you meet constantly in Go rests on exactly this multiple-return mechanism.

In real-world development, getting comfortable with this makes idiomatic Go error handling much easier to read.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Go directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)