Return

Chris Angelico rosuav at gmail.com
Tue Dec 7 17:07:15 EST 2021


On Wed, Dec 8, 2021 at 9:04 AM dn via Python-list
<python-list at python.org> wrote:
>
> plus Python, unlike some other languages, allows us to return multiple
> values, either as a collection or as an implied-tuple:
>
> def function_list():
>     a_list = [ i for i in range( 9 ) ]
>     return a_list
>
> def function_multiples():
>     a = 1
>     b = 2
>     c = 3
>     return a, b, c
>
> thus:
>
> x, y, z = function_multiples()

Not sure what you mean by "implied". You're returning a tuple formed
from three values, and then unpacking that into three destinations.
Since, at a technical level, a function can only return one value,
returning a tuple is the standard way to return more than one thing.

ChrisA


More information about the Python-list mailing list