How to Return Multiple Values from a Function in Python

If you want one Python function to give back more than one result, the most common solution is simple: return the values separated by commas.

In practice, Python usually packs those values into a tuple. You can then unpack that tuple into separate variables.

Quick answer #

def get_name_and_age():
    return "Alice", 25

name, age = get_name_and_age()

print(name)
print(age)

Output:

Alice
25

In Python, returning multiple values usually means returning a tuple. You can unpack the result into separate variables.

What this page helps you do #

This page shows you how to:

  • Return two or more values from one function
  • Store the returned values in separate variables
  • Understand that Python usually returns a tuple
  • Choose between a tuple, list, or dictionary based on clarity

If you are new to functions, see Python functions explained first.

The simplest way: return values separated by commas #

The easiest way to return multiple values is to put them after return, separated by commas.

def get_coordinates():
    return 10, 20

result = get_coordinates()
print(result)
print(type(result))

Output:

(10, 20)
<class 'tuple'>

Even though you wrote return 10, 20, Python created one tuple containing both values.

This works well when:

  • You have a small number of returned values
  • The meaning of each value is clear
  • The order is easy to remember

Here is another example:

def get_min_and_max():
    return 3, 9

values = get_min_and_max()
print(values)

Output:

(3, 9)

If you want to understand function return values more clearly, read return values in Python functions.

How to unpack the returned values #

Unpacking means storing each returned item in its own variable.

def get_name_and_age():
    return "Alice", 25

name, age = get_name_and_age()

print(name)
print(age)

Output:

Alice
25

This is often easier to read than using a single variable:

def get_name_and_age():
    return "Alice", 25

result = get_name_and_age()

print(result[0])
print(result[1])

Output:

Alice
25

Unpacking is usually better for beginners because the variable names make the result clearer.

Important rule #

The number of variables must match the number of returned values.

This works:

def get_dimensions():
    return 1920, 1080

width, height = get_dimensions()
print(width)
print(height)

This does not work:

def get_dimensions():
    return 1920, 1080

width = get_dimensions()

The code above is valid Python, but width will contain the whole tuple, not just the first value.

If you actually want separate values, you must unpack them.

Returning a tuple explicitly #

You can also write the tuple with parentheses.

def get_status():
    return ("success", 200)

message, code = get_status()

print(message)
print(code)

Output:

success
200

This behaves the same as:

def get_status():
    return "success", 200

In most cases, parentheses are optional. Many programmers still use them because they make it more obvious that the function returns a tuple.

If tuples are new to you, see what is a tuple in Python.

When to return a list or dictionary instead #

A tuple is not always the clearest choice.

Return a list when you have similar items #

Use a list when the function returns a collection of values of the same kind.

def get_scores():
    return [85, 90, 78]

scores = get_scores()
print(scores)

Output:

[85, 90, 78]

A list makes sense here because the result is one group of similar items.

Return a dictionary when names matter #

Use a dictionary when each returned value needs a label.

def get_user():
    return {
        "name": "Alice",
        "age": 25,
        "country": "Canada"
    }

user = get_user()
print(user["name"])
print(user["age"])
print(user["country"])

Output:

Alice
25
Canada

A dictionary is often easier to read when:

  • You return many values
  • The order is hard to remember
  • The meaning of each value matters more than position

Compare these two styles:

def get_user_tuple():
    return "Alice", 25, "Canada"

name, age, country = get_user_tuple()
print(name, age, country)
def get_user_dict():
    return {"name": "Alice", "age": 25, "country": "Canada"}

user = get_user_dict()
print(user["name"], user["age"], user["country"])

Both work. Choose the one that makes your code easier to understand.

Common errors when returning multiple values #

There are a few beginner mistakes to watch for.

Unpacking into too many variables #

def get_point():
    return 5, 10

x, y, z = get_point()

This raises a ValueError because the function returned only 2 values, but you tried to store them in 3 variables.

Unpacking into too few variables #

def get_point():
    return 5, 10

x = get_point()
print(x)

This does not raise an error, but x becomes the whole tuple:

(5, 10)

The real unpacking error happens when you do this:

def get_point():
    return 5, 10

x, = get_point()

This raises a ValueError because Python expected 1 value but got 2.

For fixes, see:

Returning different numbers of values #

Be careful not to return 1 value in one case and 2 values in another.

def get_data(found):
    if found:
        return "Alice", 25
    return "Not found"

This can confuse the code that calls the function:

name, age = get_data(False)

That code will fail because the function did not always return the same kind of result.

A clearer version would be:

def get_data(found):
    if found:
        return "Alice", 25
    return None, None

name, age = get_data(False)
print(name)
print(age)

Output:

None
None

Forgetting the return order #

If your function returns values in a fixed order, make sure that order stays consistent.

def get_size():
    return 800, 600  # width, height

width, height = get_size()

If you later change the function to return height first, your code may still run but produce wrong results.

Best practices for beginners #

When returning multiple values from a function:

  • Keep the return order consistent
  • Use tuple unpacking for short, simple results
  • Use dictionaries when names matter more than order
  • Use clear variable names
  • Keep the returned structure the same in all code paths

Good example:

def get_product():
    return "Book", 12.99

product_name, price = get_product()
print(product_name)
print(price)

Less clear example:

def get_product():
    return "Book", 12.99

x, y = get_product()
print(x)
print(y)

The second example works, but x and y do not tell the reader what the values mean.

Common mistakes #

These problems often cause confusion:

  • Trying to use multiple variables without unpacking the returned result
  • Returning a different number of values in different code paths
  • Confusing tuple return values with separate return statements
  • Using unclear value order such as return x, y without meaningful names

If you want a refresher on what a return value is, read what is a return value in Python.

FAQ #

Does Python really return multiple values? #

Usually, Python returns one tuple object that contains multiple values.

Do I need parentheses when returning multiple values? #

No. Parentheses are optional in most return statements, but they can improve readability.

Can I return a list instead of a tuple? #

Yes. A list is useful when you want a collection of similar items that may be changed later.

Why do I get “too many values to unpack”? #

Your function returned more items than the number of variables on the left side.

For more complex results, a dictionary is often easier to read because each value has a key.

See also #

Press Esc to close