Lambda returning tuple question, multi-expression
Cameron Simpson
cs at cskk.id.au
Thu Mar 9 16:37:49 EST 2023
On 09Mar2023 09:06, Alan Gauld <learn2program at gmail.com> wrote:
>Also layout is all important here. It could get very messy to read if
>indentation isn't clear. You only have to look at some Javascript code
>with function definitions as arguments to functions to see how clunky
>that can be.
Just a note that some code formatters use a trailing comma on the last
element to make the commas fold points. Both yapf (my preference) and
black let you write a line like (and, indeed, flatten if short enough):
( a, b, c )
but if you write:
( a, b, c, )
they'll fold the lines like:
( a,
b,
c,
)
in varying flavours of indentation depending on tuning. The point being
that if, like me, you often have a code formatter active-on-save it can
be hinted to nicely present complex tuples (or parameter lists and
imports).
It isn't magic, but can be quite effective.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list