Ad space (banner)
🐍Python Lessons
Lesson 48 / 69

Functions That Return Multiple Values (tuples)

This lesson covers returning multiple values from a function using tuples, so a single function can hand back several results at once. It's written for anyone searching "Python return multiple values tuple".

Just writing return a, b in a Python function bundles up multiple values into a tuple and returns them together. Think of it like handing over a single box containing two cards — a name and a score. What other languages require wrapping in an array or object to accomplish, Python lets you do just by separating values with commas.

The sample code's min_max function returns the tuple min(nums), max(nums), which the caller unpacks with smallest, largest = min_max(...). This is a signature example of Python's readability — and if you want to return three or more values, the same comma-separated pattern still works.

A common beginner mistake is not realizing what comes back is actually a single tuple object. Capturing it in one variable, as in result = min_max(nums), means result holds the tuple (smallest, largest) directly, and you'd access it by index, like result[0].

For anything that naturally comes as a pair of values, like coordinates (x, y) or a range (min, max), this pattern is used constantly in real work. Unpacking into clearly-named variables also makes the code's intent much easier to follow.

Python
OUTPUT

💡 The Python engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)