Functions & basics
Medium
Return multiple values
Return a tuple of results and unpack them at the call site.
How it works
Python functions can return several values by separating them with commas — the caller receives a tuple.
Tuple unpacking keeps call sites readable: min_val, max_val = bounds(data).
Name returned values clearly; a small dataclass or dict is better when you return many fields.
def min_max(values):
if not values:
return None, None
return min(values), max(values)
data = [3, 9, 1, 7]
lo, hi = min_max(data)
print(f"range: {lo} .. {hi}")
Sponsored
Sponsored
Reserved space — layout preview until AdSense is connected