🌐
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?
In summary, you can return multiple values in Python using tuples, lists, dictionaries, objects or namedtuples, generators, or multiple return statements.
🌐
Medium
medium.com β€Ί @1511425435311 β€Ί multiple-parameters-and-return-values-d241100e76f6
Exploring Multiple Parameters and Return Values in Python 🐍 | by Miguel de la Vega | Medium
December 29, 2023 - By specifying the index, you can ... of the tuple using zero-indexing. ... Python functions can return multiple values by using tuples....
Discussions

What is the best way to return multiple values from a function?
You can return any data type you want. Most of the time something like a tuple (eg. (404, "not found")) or a dict (eg. {"code": 404, "message": "not found"}) should work well. Sometimes, namedtuples or the more complex dataclasses are better to keep everything in order. More on reddit.com
🌐 r/learnpython
3
6
November 8, 2021
programming languages - Why multiple return values is not a common thing? - Computer Science Stack Exchange
I suspect that this origin of functions is the reason why multiple return values are not so common. That said, it's easy to emulate them in several ways (by returning a tuple, or by having several output parameters, i.e. ones passed by reference), and some common modern languages (such as Python) ... More on cs.stackexchange.com
🌐 cs.stackexchange.com
Can a function return more than 1 value in Python
I would side with the argument that if you explicitly and literally ask "can a function return more than 1 value", the answer is yes, because whether those values are transported inside a single tuple object is irrelevant. You return >1 values from the function, and you receive >1 values on the calling side. Now, if you're asking "can a function return more than 1 object", I would guess (not nearly enough of an expert to say with certainty) the answer is now because, as you say, a function actually returns a tuple holding the different values, which is a single object, which is then received and unpacked on the calling side. So, perhaps the discussion is more semantic than technical? Not exactly uncommon with school student/teacher arguments, in my experience :P More on reddit.com
🌐 r/Python
28
28
March 25, 2021
When you first discover that in Python a function can return multiple values
Python can't return multiple values. A tuple is a single data structure, that can contain multiple values. That is in no way multiple values. Quite frankly, no language can return multiple values. They can only return data structures that can contain multiple values. Edit: I think people misunderstand what I mean by being unable to return multiple values. You cannot return two completely different values into one memory address. As a result, you can't return two completely independent values into one variable, and/or manipulate them. You can return multiple values to multiple memory pointers, but not to one. In that regard, no language, not even assembly, can write two independently functioning objects into one memory address More on reddit.com
🌐 r/ProgrammerHumor
107
1022
October 17, 2019
🌐
Codecademy
codecademy.com β€Ί learn β€Ί flask-introduction-to-python β€Ί modules β€Ί learn-python3-functions β€Ί cheatsheet
Introduction to Python: Functions Cheatsheet | Codecademy
If the function is invoked without a value for a specific argument, the default value will be used. ... Python functions are able to return multiple values using one return statement.
🌐
scikit-learn
scikit-learn.org β€Ί stable β€Ί modules β€Ί model_evaluation.html
3.4. Metrics and scoring: quantifying the quality of predictions β€” scikit-learn 1.8.0 documentation
functions ending with _error, _loss, or _deviance return a value to minimize, the lower the better. When converting into a scorer object using make_scorer, set the greater_is_better parameter to False (True by default; see the parameter description below). You can create your own custom scorer object using make_scorer. ... You can build a completely custom scorer object from a simple python function using make_scorer, which can take several parameters:
🌐
Replit
replit.com β€Ί home β€Ί discover β€Ί how to return multiple values in python
How to return multiple values in Python
3 weeks ago - The get_user_info function showcases Python's most direct method for returning multiple items. When you list variables like name, age, is_admin after the return keyword, Python automatically packs them into a tuple.
🌐
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 performs multiple computations and returns the results as a tuple. Call the function and directly unpack the values into multiple variables.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί g-fact-41-multiple-return-values-in-python
Returning Multiple Values in Python - GeeksforGeeks
... 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
🌐
W3Resource
w3resource.com β€Ί python-interview β€Ί how-do-you-return-values-from-a-function-in-python.php
Returning Values from Python Functions: Single and Multiple
August 12, 2023 - The values should be separated by commas after the return statement. ... def add_subtract_two_nums(x, y): add_result = x + y sub_result = x - y return add_result, sub_result result1, result2 = add_subtract_two_nums(25, 9) print(result1) # Output: ...
Find elsewhere
🌐
Pynerds
pynerds.com β€Ί return-multiple-values-in-python-functions
Return multiple values In Python functions
We can simulate the return statement to look like it is returning multiple values by returning the values as a tuple.
🌐
Codedamn
codedamn.com β€Ί news β€Ί python
How To Return Multiple Values in Python?
July 2, 2023 - Tuple assignment allows us to assign multiple values at once. For example, if a function returns a tuple (John Doe, 28), we can use tuple assignment like this: name, age = profile(). name will be assigned John Doe, and age will be assigned 28.
🌐
Livestudentprojects
livestudentprojects.com β€Ί python β€Ί python-program-to-return-multiple-values-from-a-function
Python Program to Return Multiple Values From a Function – Live student Projects
The provided Python code demonstrates how to return multiple values from a function in Python using tuples. It defines a function named multiple_values() that encapsulates three different values: an integer (value1), a string (value2), and a list (value3). These values are then returned from ...
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί math.html
math β€” Mathematical functions
5 days ago - Return the floor of x, the largest integer less than or equal to x. If x is not a float, delegates to x.__floor__, which should return an Integral value. ... Fused multiply-add operation. Return (x * y) + z, computed as though with infinite precision and range followed by a single round to the float format.
🌐
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 - In Python 3.9 and later, you can use built-in tuple data structure. On older versions, you need to use typing.Tuple in your annotations. Now, consider a scenario where you want to build on the previous example. You aim to declare a function whose return value incorporates multiple pieces of data of various types.
Top answer
1 of 4
6

Functions are traditionally thought of as returning a single value - in math. Of course several values form a tuple, but oftentimes in math we are dealing with real-valued functions. I suspect that this origin of functions is the reason why multiple return values are not so common. That said, it's easy to emulate them in several ways (by returning a tuple, or by having several output parameters, i.e. ones passed by reference), and some common modern languages (such as Python) natively support this construction.

2 of 4
7

Having multiple return values is preferable. Lacking them is bad design, plain and simple. However, we should clear up the misconception that such a thing even exists in the sense you are thinking of.

In languages based on the typed lambda-calculus (the progenitor programming languages), e.g. ML-family, Haskell, a function (lambda abstraction) only accepts a single argument and "returns" (more formally, evaluates to) a single result. So how can we create a function that seems to take or return multiple values?

The answer is that we can "glue" values together by using product types. If A and B are both types, then the product type $A \times B$ contains all tuples of the form $(a, b)$, where $a: A$ and $b: B$.

Thus, to create a function multiply that multiplies two integers together, we give it the type multiply: int * int -> int. It accepts a single argument which happens to be a tuple. Likewise, a function split that splits a list into two would have type split: a list -> a list * a list.

Maybe 30 years ago implementation was a valid concern in including such a feature. According to the C calling convention cedl (and it is just that, a convention - no god ordained it), the return value is stored in a special register, usually EAX. Certainly, this is extremely fast to read and write, so the idea has some merit.

But it is too limiting, as you point out, and there is no reason we need to follow this rule nowadays. For example, we could instead use the following policy: for a small number of return values, use a set of specified registers (we have more registers for use now than in the 80s). For larger data, we could return a pointer to a location in memory. I don't know what's best; I'm not a compiler writer. But the archaic C calling convention should have no influence on the semantics of modern languages.

🌐
W3Schools
w3schools.com β€Ί python β€Ί python_variables_multiple.asp
Python Variables - Assign Multiple Values
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Note: Make sure the number of variables matches the number of values, or else you will get an error. And you can assign the same value to multiple variables in one line:
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί itertools.html
itertools β€” Functions creating iterators for efficient looping
3 days ago - ... Make an iterator that returns elements from the first iterable until it is exhausted, then proceeds to the next iterable, until all of the iterables are exhausted. This combines multiple data sources into a single iterator.
🌐
Boot.dev
boot.dev β€Ί lessons β€Ί 64266f19-9783-44c1-b63b-01f40ae9a0b8
Learn to Code in Python: Multiple Parameters | Boot.dev
Complete the triple_attack function by returning the sum of its parameters, damage_one, damage_two, and damage_three. Remember to indent the code inside the function. The pass statement is a placeholder that does nothing. Replace it with your code. The attack damage values (attack_one to attack_six) are already passed to the two triple_attack function calls for you.
🌐
Sololearn
sololearn.com β€Ί en β€Ί Discuss β€Ί 2184800 β€Ί can-a-function-in-python-return-multiple-values
Can a function in Python return multiple values? | Sololearn: Learn to code for FREE!
... Hello, no it is not possible. Only 1 value. So you must rely on tuples etc. ... Yeild generator does help you return every iteration value from loop in a function.. ... How many time is necessary to learn Python?
🌐
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