How to Return Two Values from a Function in Python
A Python function can hand back two results at once: write them after return with a comma between them, and catch them in two names when you call it. Behind the scenes, Python packs them into a tuple. This guide returns the lowest and highest number of a list, on Python 3.15.2.
Syntax
def <function>(<parameters>):
return <value 1>, <value 2>
<name 1>, <name 2> = <function>(<arguments>)
| Part | What it means |
|---|---|
return <value 1>, <value 2> | Returns both values, packed into one tuple |
<name 1>, <name 2> = ... | Unpacks the tuple: the first value goes to the first name, the second to the second |
The Python tutorial calls this tuple packing, "the values 12345, 54321 and 'hello!' are packed together in a tuple", and its reverse "sequence unpacking".
The Example
lowest_and_highest takes a list of numbers and returns its smallest and largest. The script catches them in two names, then prints the function's result as it is.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
def lowest_and_highest(numbers):
return min(numbers), max(numbers)
low, high = lowest_and_highest([7, 2, 9, 4])
print(low, high)
print(lowest_and_highest([7, 2, 9, 4]))

Step 2: Run It
uv run python min_max.py
2 9
(2, 9)

low got 2 and high got 9. Printed without unpacking, the result shows what the function really returns: the tuple (2, 9). The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Unpacking into the wrong number of names: low, middle, high = lowest_and_highest(...) | ValueError: not enough values to unpack (expected 3, got 2) | Use as many names as the function returns |
Writing two return lines | The function stops at the first one, so the second never runs | Put both values in one return, separated by a comma |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
not enough values to unpack or too many values to unpack | The number of names doesn't match the number of values | Count the values after return |
FAQ
How do I write the type hint?
As a tuple of the two types: def lowest_and_highest(numbers: list[int]) -> tuple[int, int]:.
Can I keep the result in one name?
Yes. result = lowest_and_highest([7, 2, 9, 4]) keeps the tuple, and print(result[0], result[1]) printed 2 9.
Conclusion
return min(numbers), max(numbers) returned two values packed into the tuple (2, 9), and low, high = ... unpacked them into two names. Match the number of names to the number of values.
Additional Resources
- Tuples and sequences — packing and unpacking.
- The return statement — the reference.
