[Python-ideas] Allow function to return multiple values

Thomas Nyberg tomuxiong at gmx.com
Thu Jun 1 10:57:54 EDT 2017


On 06/01/2017 07:17 AM, joannah nanjekye wrote:
> a function that returns two values something like this:
> 
> def return_multiplevalues(num1, num2):
>      return num1, num2
> 
>  I noticed that this actually returns a tuple of the values which I did
> not want in the first place.I wanted python to return two values in
> their own types so I can work with them as they are but here I was stuck
> with working around a tuple.
> 

Why not just unpack the values? E.g.

test.py
-----------------
def f(a, b):
    return a, b

a, b = f(1, 2)

print(a)
print(b)
-----------------

$ python3 test.py
1
2

Cheers,
Thomas


More information about the Python-ideas mailing list