Style qeustion: Multiple return values
Terry Reedy
tjreedy at udel.edu
Mon Apr 12 06:08:20 EDT 2021
On 4/12/2021 4:29 AM, 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()
No. Parentheses are for grouping (and separation from surrounding code).
() and (1,) (can be though of as) group(ing) the a zero-width space
and one-comma pair respectively and separate them from the rest of the code.
--
Terry Jan Reedy
More information about the Python-list
mailing list