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
- Positional and Keyword Arguments
- Default Argument Values
- Returning Multiple Values
- Reading Function Signatures