Absolutely (for the example you provided).

Tuples are first class citizens in Python

There is a builtin function divmod() that does exactly that.

q, r = divmod(x, y) # ((x - x%y)/y, x%y) Invariant: div*y + mod == x

There are other examples: zip, enumerate, dict.items.

for i, e in enumerate([1, 3, 3]):
    print "index=%d, element=%s" % (i, e)

# reverse keys and values in a dictionary
d = dict((v, k) for k, v in adict.items()) # or 
d = dict(zip(adict.values(), adict.keys()))

BTW, parentheses are not necessary most of the time. Citation from Python Library Reference:

Tuples may be constructed in a number of ways:

  • Using a pair of parentheses to denote the empty tuple: ()
  • Using a trailing comma for a singleton tuple: a, or (a,)
  • Separating items with commas: a, b, c or (a, b, c)
  • Using the tuple() built-in: tuple() or tuple(iterable)

Functions should serve single purpose

Therefore they should return a single object. In your case this object is a tuple. Consider tuple as an ad-hoc compound data structure. There are languages where almost every single function returns multiple values (list in Lisp).

Sometimes it is sufficient to return (x, y) instead of Point(x, y).

Named tuples

With the introduction of named tuples in Python 2.6 it is preferable in many cases to return named tuples instead of plain tuples.

>>> import collections
>>> Point = collections.namedtuple('Point', 'x y')
>>> x, y = Point(0, 1)
>>> p = Point(x, y)
>>> x, y, p
(0, 1, Point(x=0, y=1))
>>> p.x, p.y, p[0], p[1]
(0, 1, 0, 1)
>>> for i in p:
...   print(i)
...
0
1
Answer from jfs on Stack Overflow
Top answer
1 of 9
119

Absolutely (for the example you provided).

Tuples are first class citizens in Python

There is a builtin function divmod() that does exactly that.

q, r = divmod(x, y) # ((x - x%y)/y, x%y) Invariant: div*y + mod == x

There are other examples: zip, enumerate, dict.items.

for i, e in enumerate([1, 3, 3]):
    print "index=%d, element=%s" % (i, e)

# reverse keys and values in a dictionary
d = dict((v, k) for k, v in adict.items()) # or 
d = dict(zip(adict.values(), adict.keys()))

BTW, parentheses are not necessary most of the time. Citation from Python Library Reference:

Tuples may be constructed in a number of ways:

  • Using a pair of parentheses to denote the empty tuple: ()
  • Using a trailing comma for a singleton tuple: a, or (a,)
  • Separating items with commas: a, b, c or (a, b, c)
  • Using the tuple() built-in: tuple() or tuple(iterable)

Functions should serve single purpose

Therefore they should return a single object. In your case this object is a tuple. Consider tuple as an ad-hoc compound data structure. There are languages where almost every single function returns multiple values (list in Lisp).

Sometimes it is sufficient to return (x, y) instead of Point(x, y).

Named tuples

With the introduction of named tuples in Python 2.6 it is preferable in many cases to return named tuples instead of plain tuples.

>>> import collections
>>> Point = collections.namedtuple('Point', 'x y')
>>> x, y = Point(0, 1)
>>> p = Point(x, y)
>>> x, y, p
(0, 1, Point(x=0, y=1))
>>> p.x, p.y, p[0], p[1]
(0, 1, 0, 1)
>>> for i in p:
...   print(i)
...
0
1
2 of 9
28

Firstly, note that Python allows for the following (no need for the parenthesis):

q, r = divide(22, 7)

Regarding your question, there's no hard and fast rule either way. For simple (and usually contrived) examples, it may seem that it's always possible for a given function to have a single purpose, resulting in a single value. However, when using Python for real-world applications, you quickly run into many cases where returning multiple values is necessary, and results in cleaner code.

So, I'd say do whatever makes sense, and don't try to conform to an artificial convention. Python supports multiple return values, so use it when appropriate.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ g-fact-41-multiple-return-values-in-python
Returning Multiple Values in Python - GeeksforGeeks
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.
Published ย  July 1, 2025
Discussions

python - Is there a convention for returning multiple items? - Software Engineering Stack Exchange
Similarly, a function that returns ... simply returning a tuple. ... The first case is merely syntactic sugar for the latter; both receive a triple as an argument, but the first pattern-matches on its argument to perform automatic destructuring into its constituent components. Thus, even languages without full-on general pattern-matching admit some form of basic pattern matching on some of their types (Python admits ... More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
August 6, 2016
Implicit tuple return type - Ideas - Discussions on Python.org
Before: def go() -> tuple[int, str]: return 1, "A" After: def go() -> int, str: return 2, "B" I donโ€™t know what else to say and I think it just looks good :slight_smile: More on discuss.python.org
๐ŸŒ discuss.python.org
3
May 8, 2024
Is there a way to annotate the return types of a function that returns multiple values
If it returns multiple values at the same time, then it's Tuple. If it might return an int or it might return a str then it's Union. More on reddit.com
๐ŸŒ r/Python
47
50
August 31, 2022
Python mysql query returns tuple and not string or int
Return myresult[0] ? More on reddit.com
๐ŸŒ r/Python
6
0
October 31, 2019
๐ŸŒ
Reddit
reddit.com โ€บ r/programmerhumor โ€บ when you first discover that in python a function can return multiple values
r/ProgrammerHumor on Reddit: When you first discover that in Python a function can return multiple values
October 17, 2019 - Now, what's happening in the background is the second one is returning a single tuple (1, 2) but you can assign them to separate variables in a single function call that uses syntax implying it is returning two. So, the joke is that python can return multiple values through syntax that in reality is making it return a single tuple.
๐ŸŒ
Runestone Academy
runestone.academy โ€บ ns โ€บ books โ€บ published โ€บ fopp โ€บ Tuples โ€บ TuplesasReturnValues.html
13.4. Tuples as Return Values โ€” Foundations of Python Programming
Define a function called info with the following required parameters: name, age, birth_year, year_in_college, and hometown. The function should return a tuple that contains all the inputted information.
Top answer
1 of 2
19

I think the choices need to be considered strictly from the caller's point of view: what is the consumer most likely to need to do?

And what are the salient features of each collection?

  • The tuple is accessed in order and immutable
  • The list is accessed in order and mutable
  • The dict is accessed by key

The list and tuple are equivalent for access, but the list is mutable. Well, that doesn't matter to me the caller if I'm going to immediately unpack the results:

score, top_player = play_round(players)
# or
idx, record = find_longest(records)

There's no reason here for me to care if it's a list or a tuple, and the tuple is simpler on both sides.

On the other hand, if the returned collection is going to be kept whole and used as a collection:

points = calculate_vertices(shape)
points.append(another_point)
# Make a new shape

then it might make sense for the return to be mutable. Homogeneity is also an important factor here. Say you've written a function to search a sequence for repeated patterns. The information I get back is the index in the sequence of the first instance of the pattern, the number of repeats, and the pattern itself. Those aren't the same kinds of thing. Even though I might keep the pieces together, there's no reason that I would want to mutate the collection. This is not a list.

Now for the dictionary.

the last one creates more readable code because you have named outputs

Yes, having keys for the fields makes heterogenous data more explicit, but it also comes with some encumbrance. Again, for the case of "I'm just going to unpack the stuff", this

round_results = play_round(players)
score, top_player = round_results["score"], round_results["top_player"]

(even if you avoid literal strings for the keys), is unnecessary busywork compared to the tuple version.

The question here is threefold: how complex is the collection, how long is the collection going to be kept together, and are we going to need to use this same kind of collection in a bunch of different places?

I'd suggest that a keyed-access return value starts making more sense than a tuple when there are more than about three members, and especially where there is nesting:

shape["transform"]["raw_matrix"][0, 1] 
# vs.
shape[2][4][0, 1]

That leads into the next question: is the collection going to leave this scope intact, somewhere away from the call that created it? Keyed access over there will absolutely help understandability.

The third question -- reuse -- points to a simple custom datatype as a fourth option that you didn't present.

Is the structure solely owned by this one function? Or are you creating the same dictionary layout in many places? Do many other parts of the program need to operate on this structure? A repeated dictionary layout should be factored out to a class. The bonus there is that you can attach behavior: maybe some of the functions operating on the data get encapsulated as methods.

A fifth good, lightweight, option is namedtuple(). This is in essence the immutable form of the dictionary return value.

2 of 2
1

Don't think about functions returning multiple arguments. Conceptually, it is best to think of functions as both receiving and returning a single argument. A function that appears to accept multiple arguments actually receives just a single argument of tuple (formally product) type. Similarly, a function that returns multiple arguments is simply returning a tuple.

In Python:

def func(a, b, c):
  return b, c

could be rewritten as

def func(my_triple):
  return (my_triple[1], my_triple[2])

to make the comparison obvious.

The first case is merely syntactic sugar for the latter; both receive a triple as an argument, but the first pattern-matches on its argument to perform automatic destructuring into its constituent components. Thus, even languages without full-on general pattern-matching admit some form of basic pattern matching on some of their types (Python admits pattern-matching on both product and record types).


To return to the question at hand: there is no single answer to your question, because it would be like asking "what should be the return type of an arbitrary function"? It depends on the function and the use case. And, incidentally, if the "multiple return values" are really independent, then they should probably be computed by separate functions.

๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
3 days ago - The __next__() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable.
Find elsewhere
๐ŸŒ
Python.org
discuss.python.org โ€บ ideas
Implicit tuple return type - Ideas - Discussions on Python.org
May 8, 2024 - Before: def go() -> tuple[int, str]: return 1, "A" After: def go() -> int, str: return 2, "B" I donโ€™t know what else to say and I think it just looks good ๐Ÿ™‚
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ typing.html
typing โ€” Support for type hints
4 days ago - A type variable tuple, in contrast, allows parameterization with an arbitrary number of types by acting like an arbitrary number of type variables wrapped in a tuple. For example: # T is bound to int, Ts is bound to () # Return value is (1,), which has type tuple[int] move_first_element_to_last(tup=(1,)) # T is bound to int, Ts is bound to (str,) # Return value is ('spam', 1), which has type tuple[str, int] move_first_element_to_last(tup=(1, 'spam')) # T is bound to int, Ts is bound to (str, float) # Return value is ('spam', 3.0, 1), which has type tuple[str, float, int] move_first_element_to_last(tup=(1, 'spam', 3.0)) # This fails to type check (and fails at runtime) # because tuple[()] is not compatible with tuple[T, *Ts] # (at least one element is required) move_first_element_to_last(tup=())
๐ŸŒ
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 - Notice that we didnโ€™t use parentheses in the return statement. Thatโ€™s because you can return a tuple by separating each item with a comma, as shown in the above example.
๐ŸŒ
Pierian Training
pieriantraining.com โ€บ home โ€บ how to return tuple in python
How to Return Tuple in Python - Pierian Training
June 18, 2023 - In this example, the `get_name_and_age` function returns a tuple containing two values โ€“ the name and age. We then assign this tuple to the variable `result` and print it out. Overall, tuples are a useful data structure in Python that allow you to store collections of elements that cannot be modified once created.
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ is there a way to annotate the return types of a function that returns multiple values
r/Python on Reddit: Is there a way to annotate the return types of a function that returns multiple values
August 31, 2022 - You can have multiple return statements and all of them can be of the same type. Union is used to say that your return can be of more than one type. ... What kind of values? You could use a tuple or a list(if they're all the same type of value) or something like that.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_tuples_unpack.asp
Python - Unpack Tuples
This is called "packing" a tuple: ... But, in Python, we are also allowed to extract the values back into variables.
๐ŸŒ
Quora
quora.com โ€บ Is-returning-multiple-variables-in-Python-considered-poor-programming
Is returning multiple variables in Python considered 'poor' programming? - Quora
Answer (1 of 6): Nope; it is good programming. This question can be paraphrased as โ€œIs returning a tuple in Python considered โ€˜poorโ€™ programming?โ€, because that is exactly what those multiple values are - a tuple. Returning any data type cannot be considered bad practice.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_tuples.asp
Python Tuples
Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Set is a collection which is unordered, unchangeable*, and unindexed. No duplicate members. Dictionary is a collection which is ordered** and changeable. No duplicate members. *Set items are unchangeable, but you can remove and/or add items whenever you like. **As of Python version 3.7, dictionaries are ordered.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.3 documentation
As you see, on output tuples are always enclosed in parentheses, so that nested tuples are interpreted correctly; they may be input with or without surrounding parentheses, although often parentheses are necessary anyway (if the tuple is part of a larger expression).
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to return python tuple from function
How to Return Python Tuple from Function - Spark By {Examples}
May 31, 2024 - How to return a tuple from a Python function? In Python, a tuple is a collection of ordered, immutable objects and you can return a tuple from a function by enclosing the objects you want to return in parentheses.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_tuples_access.asp
Python - Access Tuple Items
This example returns the items from the beginning to, but NOT included, "kiwi": thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango") print(thistuple[:4]) Try it Yourself ยป ยท By leaving out the end value, the range will go on to the end of the tuple:
๐ŸŒ
CodeQL
codeql.github.com โ€บ codeql-query-help โ€บ python โ€บ py-mixed-tuple-returns
Returning tuples with varying lengths โ€” CodeQL query help documentation
def sum_length_product1(l): if l == []: return 0, 0 # this tuple has the wrong length else: val = l[0] restsum, restlength, restproduct = sum_length_product1(l[1:]) return restsum + val, restlength + 1, restproduct * val def sum_length_product2(l): if l == []: return 0, 0, 1 # this tuple has the correct length else: val = l[0] restsum, restlength, restproduct = sum_length_product2(l[1:]) return restsum + val, restlength + 1, restproduct * val ยท Python Language Reference: Function definitions.
๐ŸŒ
QASource
blog.qasource.com โ€บ software-development-and-qa-tips โ€บ how-to-return-multiple-values-in-python
How To Return Multiple Values From a Function in Python?
Using Multiple Return Statements: You can directly return multiple values separated by commas, which Python automatically packs into a tuple.