Style qeustion: Multiple return values

dn PythonList at DancesWithMice.info
Mon Apr 12 06:19:00 EDT 2021


On 12/04/2021 20.29, Steve Keller wrote:
> Just a short style question: When returning multiple return values, do
> you use parenthesis?
> 
> E.g. would you write
> 
>     def foo():
>         return 1, 2
> 
>     a, b = foo()
> 
> or do you prefer
> 
>     def foo():
>         return (1, 2)
> 
>     (a, b) = foo()



Steve

The data-structure being returned is a tuple. The tuple is defined by
the comma-separator - not the parentheses.

Of course, the way you use them (first example) involves "unpacking"
after the tuple 'crosses' the equals/assignment.

Thus, the answer to your question is a matter of style, and thus the
understanding of those who might read the code.

FWIW: I leave them out because it is easier on my eyes whilst scanning
the line of code.
-- 
Regards,
=dn


More information about the Python-list mailing list