"1,+2,", but not "(1,)+2,"

Chris Angelico rosuav at gmail.com
Fri Jul 31 14:38:56 EDT 2020


On Sat, Aug 1, 2020 at 4:31 AM Jon Ribbens via Python-list
<python-list at python.org> wrote:
>
> On 2020-07-31, Bart <bc at freeuk.com> wrote:
> > Not sure about the trailing commas on each. It seems Python ignores
> > trailing commas on tuple constructors, so that the A,B, would be a
> > 2-tuple, and A+B, would have been a 1-tuple if A+B had been legal.
>
> It's not just tuples, it's lists, sets, dictionaries, etc.

And function parameters and basically anything that permits a
comma-separated sequence. Or any other sort of sequence. You can have
multiple simple statements on one line, separated by semicolons - and
it's legal to have a spare semi at the end.

It's REALLY annoying to run into those few cases where that doesn't
work (JSON, and the SQL "create table" statement, and a handful of
others).

ChrisA


More information about the Python-list mailing list