You can use x = func()[0] to return the first value, x = func()[1] to return the second, and so on.

If you want to get multiple values at a time, use something like x, y = func()[2:4].

Answer from Luke Woodward on Stack Overflow
🌐
Real Python
realpython.com › python-return-statement
The Python return Statement: Usage and Best Practices – Real Python
June 14, 2024 - A return statement consists of the return keyword followed by an optional return value. The return value of a Python function can be any Python object, and you can use them to perform further computation in your programs. Using the return statement effectively is a core skill if you want to code custom functions that are Pythonic and robust. ... You use return to send objects from your functions back to the caller code. You can use return to return one single value or multiple values separated by commas...
🌐
Note.nkmk.me
note.nkmk.me › home › python
How to Return Multiple Values from a Function in Python | note.nkmk.me
April 23, 2025 - In Python, comma-separated values are treated as tuples even without parentheses, unless parentheses are required by syntax. Therefore, the function in the example above returns a tuple. Note that it is actually the comma which makes a tuple, not the parentheses. The parentheses are optional, ...
Top answer
1 of 2
19

You can use star unpacking to gather all additional return values into a list:

x, *y = fun()

x will contain the first return value. y will be a list of the remaining values. y will be empty if there is only one return value. This particular example will only work if the function returns a tuple, even if there is only one value.

When fun always returns 1 or 2 values, you can just do

if y:
    print(y[0])
else:
    print('only one value')

If, on the other hand, you want to completely ignore the number of return values, do

*x = fun()

Now all the arguments will be gathered into the list. You can then print it with either

print(x)

or

print(*x)

The latter will pass each element as a separate argument, exactly as if you did

x, y, z = fun()
print(x, y, z)

The reason to use *x = fun() instead of just x = fun() is to get an error immediately when a function returns something that isn't a tuple. Think of it as an assertion to remind you to write fun properly.

Since this form of star unpacking only works in Python 3, your only option in Python 2 is to do

x = fun()

and to inspect the result manually.

2 of 2
1

There are several ways to get multiple return values.

Example 1:

def test_fun():
    return 1,2

def test_call():
    x, y = test_fun()
    print x
    print y

you will get correct output:

1
2

When you would like to ignore several return values, you can use * before a variable in python3.

Example 2:

def test_fun2():
    return 1,2,3

def test_call2():
    x, *y = test_fun2()
    print x
    print y

you will get the result:

1
(2, 3)
🌐
Real Python
realpython.com › python-type-hints-multiple-types
How to Use Type Hints for Multiple Return Types in Python – Real Python
March 8, 2024 - The scenarios for considering multiple ... may sometimes return no value, in which case you can use type hints to signal the occasional absence of a return value....
🌐
freeCodeCamp
freecodecamp.org › news › python-returns-multiple-values-how-to-return-a-tuple-list-dictionary
Python Return Multiple Values – How to Return a Tuple, List, or Dictionary
July 20, 2020 - To do so, return a data structure that contains multiple values, like a list containing the number of miles to run each week. def miles_to_run(minimum_miles): week_1 = minimum_miles + 2 week_2 = minimum_miles + 4 week_3 = minimum_miles + 6 return [week_1, week_2, week_3] print(miles_to_run(2)) # result: [4, 6, 8] Data structures in Python are used to store collections of data, which can be returned from functions.
Find elsewhere
🌐
Flexiple
flexiple.com › python › python-return-multiple-values
Return multiple values from a function in Python | Flexiple Tutorials - Flexiple
Python basically uses a tuple to achieve this. ... #Returning Multiple Values using Tuples def multiple(): operation = "Sum" total = 5+10 return operation, total; operation, total = multiple() print(operation, total) #Output = Sum 15
Top answer
1 of 6
20

Using the underscore for unused variables is definitely acceptable. Be warned though, in some codebases it's not an option as that identifier is reserved as shorthand for gettext. This is the most frequent objection to this style (though it's not an issue for the majority as far as I can judge). I'd still recommend it, and always use it myself.

Names like dummy or unused tend to irritate me personally, and I don't see them terribly often (in Python, that is - I know a Delphi codebase which uses dummy liberally, and it has also leaked into scripts associated with the program in question). I'd advice you against it.

Just extracting one item from the returned tuple is okay too. It also saves some hassle with getting the number of unused values right. Note though that it's has two potential downsides:

  • It doesn't blow up if the number of values is different from what you expect. This may be useful to detect mixups and typos.
  • It only works when the return value is a sequence (that's mostly tuples and lists, but let's stay general). Offhand, I know one class in my code (a 2D vector) that is iterable and yields a constant number of values (and thus can be used in unpacking assignments), but is not indexable.
2 of 6
30

Pylint has gotten me in the habit of doing it this way:

widget, _parent, _children = f()

That is, unused results have a descriptive name prefixed by _. Pylint regards locals prefixed with _ as unused, and globals or attributes prefixed with _ as private.

🌐
Drbeane
drbeane.github.io › python › pages › functions › returning_multiple.html
Returning Multiple Values — Python for Data Science
def locate(x, item): index_list = [] for i in range(0, len(x)): if x[i] == item: index_list.append(i) return (index_list, len(index_list)) A list of student grades is provided in the cell below. Call locate() five times. In each function call, pass in grades for x. For item, use each of the following values: 'A', 'B', 'C', 'D', and 'F'.
🌐
datagy
datagy.io › home › python posts › python: return multiple values from a function
Python: Return Multiple Values from a Function • datagy
December 19, 2022 - The way that this works, is that Python actually turns the values (separated by commas) into a tuple. We can see how this works by assigning the function to a variable and checking its type. # Returning Multiple Values with Tuples def return_multiple(): return 1, 2, 3 variable = return_multiple() print(type(variable)) # Returns: <class 'tuple'>
🌐
Boot.dev
boot.dev › lessons › 3c5fe40f-41e3-4d7e-a035-be67c8d83536
Learn to Code in Python: Multiple Return Values | Boot.dev
def cast_iceblast(wizard_level, start_mana): damage = wizard_level * 2 new_mana = start_mana - 10 return damage, new_mana # return two values · When calling a function that returns multiple values, you can assign them to multiple variables.
🌐
Python Land
python.land › home › tips & tricks › python return multiple values
Python Return Multiple Values • Python Land Tips & Tricks
May 16, 2023 - Here’s a runnable example of ... effect. And if you’re wondering whether you can return more than two values this way: yes, you can!...
🌐
GeeksforGeeks
geeksforgeeks.org › python › g-fact-41-multiple-return-values-in-python
Returning Multiple Values in Python - GeeksforGeeks
This is useful when a function needs to give back several related results together. Lets explore different ways to do it. Tuple is a group of values separated by commas. Python automatically packs the values into a tuple, which can then be unpacked into variables. ... Explanation: fun() returns two values as a tuple, which are unpacked into s and x and then printed. Data class is a special type of class used to store multiple ...
Published   July 1, 2025
🌐
GoLinuxCloud
golinuxcloud.com › home › python › python function return multiple values [solved]
Python function Return Multiple Values [SOLVED] | GoLinuxCloud
January 9, 2024 - If you're looking for a more readable yet lightweight approach for returning multiple values from a function, Python's namedtuple from the collections module can be a great option.
Top answer
1 of 14
697

Named tuples were added in 2.6 for this purpose. Also see os.stat for a similar builtin example.

>>> import collections
>>> Point = collections.namedtuple('Point', ['x', 'y'])
>>> p = Point(1, y=2)
>>> p.x, p.y
1 2
>>> p[0], p[1]
1 2

In recent versions of Python 3 (3.6+, I think), the new typing library got the NamedTuple class to make named tuples easier to create and more powerful. Inheriting from typing.NamedTuple lets you use docstrings, default values, and type annotations.

Example (From the docs):

class Employee(NamedTuple):  # inherit from typing.NamedTuple
    name: str
    id: int = 3  # default value

employee = Employee('Guido')
assert employee.id == 3
2 of 14
270

For small projects I find it easiest to work with tuples. When that gets too hard to manage (and not before) I start grouping things into logical structures, however I think your suggested use of dictionaries and ReturnValue objects is wrong (or too simplistic).

Returning a dictionary with keys "y0", "y1", "y2", etc. doesn't offer any advantage over tuples. Returning a ReturnValue instance with properties .y0, .y1, .y2, etc. doesn't offer any advantage over tuples either. You need to start naming things if you want to get anywhere, and you can do that using tuples anyway:

def get_image_data(filename):
    [snip]
    return size, (format, version, compression), (width,height)

size, type, dimensions = get_image_data(x)

IMHO, the only good technique beyond tuples is to return real objects with proper methods and properties, like you get from re.match() or open(file).

🌐
Python Basics
pythonbasics.org › multiple-return
Multiple return - Python Tutorial
In that case you can return variables from a function. In the most simple case you can return a single variable: Call the function with complexfunction(2,3) and its output can be used or saved. But what if you have multiple variables in a function that you want access to?