← back to unit
Medium
# basics functions
Returning More Than One Value
A function can return more than one value at once, separated by commas — then you "unpack" them into separate variables when you call it:
def min_max(a, b):
if a < b:
return a, b
else:
return b, a
smaller, bigger = min_max(9, 3)
print(smaller)
print(bigger)
prints:
3
9
Your turn: we've already read two numbers into a and b for you. Define min_max(a, b) that returns the smaller value first, then the bigger value. Call min_max, unpack the results into smaller and bigger, and print each on its own line.
💡 need a hint?
pyb-func-multi-return.py🔒 given lines are locked — write your code in between
loading...