For review: PEP 308 - If-then-else expression

Tim Peters tim.one at comcast.net
Sat Feb 8 22:10:45 CET 2003


[Paul Rubin]
> ...
> Btw, just the other night I discovered that Python has a feature that
> I first saw in C: you can enter a list or tuple with an extra comma at
> the end (like [2,3,5,] , and the extra comma is ignored.

Also for dicts, and formal and actual argument lists.  A trailing comma in a
container literal is often used as a clue to the reader that the author
*expects* the container to grow more stuff over time.  For example, a dict
mapping selected HTML tags to action routines.  When I'm in a hurry, it's
surprising how often I forget to add a trailing comma to the preceding item
when appending a new item, so in containers I expect to grow I always use a
trailing comma.  Then adding a new item usually consists of duplicating the
last line verbatim and justediting the parts that change.  The new line
inherits the trailing comma from the old line, so I save at least a
keystroke each time <wink>.

For the life of me, though, I've never found a good reason to add a trailing
comma to a formal argument list.






More information about the Python-list mailing list