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
🌐
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 - That’s because you can return a tuple by separating each item with a comma, as shown in the above example. “It is actually the comma which makes a tuple, not the parentheses,” the documentation points out.
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
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
🌐
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.
🌐
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.
🌐
Note.nkmk.me
note.nkmk.me › home › python
How to Return Multiple Values from a Function in Python | note.nkmk.me
April 23, 2025 - A tuple with one element requires a comma in Python · result = test() print(result) print(type(result)) # ('abc', 100) # <class 'tuple'> ... Each element in the returned tuple has the data type defined in the function.
🌐
Python Examples
pythonexamples.org › python-return-tuple
Python Return Tuple from Function
In this example, we shall return multiple tuples from the function using generators. def myFunction(rollnos, names): #create tuple yield (rollnos[0], names[0]) yield (rollnos[1], names[1]) tuple1, tuple2 = myFunction([1, 2], ['Mike', 'Ram']) print(tuple1) print(tuple2) ... In this tutorial of Python Examples, we learned how to return Tuple from a function, with the help of well detailed example programs.
Find elsewhere
🌐
Stanford
web.stanford.edu › class › archive › cs › cs106a › cs106a.1202 › handouts › py-tuple.html
Stanford
2. All paths should return a tuple of that same length, even if it is (None, None), so that standard looking calling code of the form (x, y) = fn(..) works without crashing should it hit the None case. Calling min2 looks like this, catching the len-2 tuple result into 2 variables. ... One handy use of tuples is the dict.items() function, which returns the entire contents of the dict as an list of len-2 (key, value) tuples.
🌐
Finxter
blog.finxter.com › home › learn python blog › python return tuple from function
Python Return Tuple From Function - Be on the Right Side of Change
August 24, 2021 - Do you need to create a function that returns a tuple but you don’t know how? No worries, in sixty seconds, you’ll know! Go! ? A Python function can return any object such as a tuple. To return a tuple, first create the tuple object within the function body, assign it to a variable your_tuple, ...
🌐
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 - How do I return multiple values from a function? r/learnpython • · r/learnpython · Subreddit for posting questions and asking for general advice about all topics related to learning python. Weekly visitors · Weekly contributions · upvotes · · comments · tuples and return ·
🌐
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.
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.org
discuss.python.org › ideas
An idea to allow implicit return of NamedTuples - Ideas - Discussions on Python.org
October 31, 2023 - In the current versions of Python, there is a convenient way to implicitly return a tuple using commas or a parenthesis-based syntax. For example: def fx(): return 1, 2 and def fx(): return (1, 2) Both of thes…
🌐
Flexiple
flexiple.com › python › python-return-multiple-values
Return multiple values from a function in Python | Flexiple Tutorials - Flexiple
#Returning Multiple Values using Tuples def multiple(): operation = "Sum" total = 5+10 return operation, total; operation, total = multiple() print(operation, total) #Output = Sum 15 · A common confusion here is that the syntax of tuple requires a pair of brackets (). Although this is true, Python does not always require brackets to identify a tuple.
🌐
Llego
llego.dev › home › blog › multiple return values tuple unpacking python guide
Multiple Return Values Tuple Unpacking Python Guide - llego.dev
June 3, 2023 - This guide covered the key aspects of multiple return values and tuple unpacking in Python. We discussed: Tuples and how to return multiple values from functions using them.
🌐
CodeQL
codeql.github.com › codeql-query-help › python › py-mixed-tuple-returns
Returning tuples with varying lengths — CodeQL query help documentation
ID: py/mixed-tuple-returns Kind: ... python-security-and-quality.qls ... A common pattern for functions returning multiple arguments is to return a single tuple containing said arguments....