[Python-ideas] Allow function to return multiple values

Terry Reedy tjreedy at udel.edu
Thu Jun 1 15:10:48 EDT 2017


On 6/1/2017 10:17 AM, joannah nanjekye wrote:

> Today I was writing an example snippet for the book and needed to write 
> 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.

Others have pointed out that you are not stuck at all.  Returning a 
tuple that can be unpacked is Python's concrete implementation of the 
abstract concept 'return multiple values'.  Note that Python's gives one 
a choice whether to keep the values bundles or to immediately unbundle them.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list