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
Answer from A. Coady on Stack Overflow
๐ŸŒ
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 related values.
Published ย  July 1, 2025
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).

๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
How to Return Multiple Values from a Function in Python | note.nkmk.me
April 23, 2025 - The same applies to three or more return values. def test2(): return 'abc', 100, [0, 1, 2] a, b, c = test2() print(a) # abc print(b) # 100 print(c) # [0, 1, 2] ... By using [], you can return a list instead of a tuple. def test_list(): return ...
๐ŸŒ
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'.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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?
Find elsewhere
๐ŸŒ
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 - In this article, weโ€™ll explore how to return multiple values from these data structures: tuples, lists, and dictionaries. A tuple is an ordered, immutable sequence. That means, a tuple canโ€™t change. Use a tuple, for example, to store information about a person: their name, age, and location. ... Hereโ€™s how youโ€™d write a function that returns a tuple. def person(): return "bob", 32, "boston" print(person()) # result: ('bob', 32, 'boston')
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ multiple-return-values
Python Program to Return Multiple Values From a Function
Python Functions ยท def name(): ... = name() print(name_1, name_2) Output ยท ('John', 'Armin') John Armin ยท When you return multiple values using comma(s), they are returned in the form of a tuple....
๐ŸŒ
Linux Hint
linuxhint.com โ€บ return_multiple_values_python_function
Return Multiple Values from A Python Function โ€“ Linux Hint
This is another option to return many values from a function. A dictionary object variable named dictVar is declared inside the function. Three values are assigned to the variable and return the dicVar to the caller. Next, the dictionary values are printed. #!/usr/bin/env python3 # Define function ...
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ python: return multiple values from a function
Python: Return Multiple Values from a Function | Career Karma
December 1, 2023 - You can return multiple values by bundling those values into a dictionary, tuple, or a list. These data types let you store multiple similar values. You can extract individual values from them in your main program.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
How do you return multiple variables in a function? - Python Help - Discussions on Python.org
December 4, 2021 - Iโ€™ve been trying to write a piece of code where 2 variables defined in the first function are returned and used in the second function. Iโ€™ve tried returning the 2 variables with a comma between them but I keep getting a โ€ฆ
๐ŸŒ
Real Python
realpython.com โ€บ python-return-statement
The Python return Statement: Usage and Best Practices โ€“ Real Python
June 14, 2024 - Note that, to return multiple values, you just need to write them in a comma-separated list in the order you want them returned. Note: If your functions needs several different return types, then youโ€™re dealing with a more complex scenario.
๐ŸŒ
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'>
๐ŸŒ
GoLinuxCloud
golinuxcloud.com โ€บ home โ€บ python โ€บ python function return multiple values [solved]
Python function Return Multiple Values [SOLVED] | GoLinuxCloud
January 9, 2024 - In this example, the add function ... in the variable result. Python allows you to return multiple values by separating return values with commas....
๐ŸŒ
Vultr
docs.vultr.com โ€บ python โ€บ examples โ€บ return-multiple-values-from-a-function
Python Program to Return Multiple Values From a Function | Vultr Docs
December 31, 2024 - Define a function that evaluates conditions and returns different sets of values depending on the outcome. Use the returned multiple values based on the condition.
๐ŸŒ
DataCamp
campus.datacamp.com โ€บ courses โ€บ introduction-to-functions-in-python โ€บ writing-your-own-functions
Multiple parameters and return values | Python
You can call the function by passing in two arguments because the function has two parameters, as declared in the function header. The order in which the arguments are passed correspond to the order of the parameters in the function header. This means that when we call raise_to_power(2, 3), ...
๐ŸŒ
Medium
martinxpn.medium.com โ€บ what-are-multiple-return-values-actually-in-python-28-100-days-of-python-82821c8de24b
What are Multiple Return Values Actually in Python? (28/100 Days of Python) | by Martin Mirakyan | Medium
April 10, 2023 - Python allows us to return several values from a function. Thus making it possible to write code like the following: def get_user_data(): return 'Anna', 23, 'anna123' name, age, id = get_user_data() print('Got the user data:', name, age, id) ...