Multiple Return in Python
Level 3112 keystrokes
This function returns multiple values as a tuple. Python allows unpacking multiple return values into separate variables.
Python code
# Define a function that returns two values1def min_max(nums): # Return min and max as a tuple (comma creates tuple)2 return min(nums), max(nums)3 # Unpack the returned tuple into two variables4lo, hi = min_max([3, 1, 4, 1, 5])# Print both values using f-string5print(f"Min: {lo}, Max: {hi}")Output
Min: 1, Max: 5
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 7(× 5)× 5:× 3_× 2"× 2{× 2}× 2[× 1]× 1