Sponsored Reserved space — layout preview until AdSense is connected

Return multiple values

Return a tuple of results and unpack them at the call site.

9 lines 4 views 0 copies Updated May 23, 2026
Try in editor

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.

Python
Try in editor
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

Run this sample

Open the browser IDE to tweak the example and see results without installing anything.

Open editor

More from Functions & basics