0Pricing
Mojo Academy · Lesson

Returning Multiple Values

Hand back tuples from a function.

More Than One Result

Sometimes a function naturally produces two answers at once. In Mojo you can hand them all back together using a tuple.

Returning a Tuple

List the values separated by commas in the return. Mojo packs them into one tuple that the caller can take apart.

fn min_max(a: Int, b: Int) -> (Int, Int):
    if a < b:
        return (a, b)
    return (b, a)

All lessons in this course

  1. Positional and Keyword Arguments
  2. Default Argument Values
  3. Returning Multiple Values
  4. Reading Function Signatures
← Back to Mojo Academy