[Python-Dev] RE: Meaning of trailing comma?
Chermside, Michael
mchermside@ingdirect.com
Wed, 4 Jun 2003 10:59:40 -0400
Hello Roman:
The list "python-dev" is not the correct place to ask questions like this. =
The list "python-list" (accessed as "python-list@python.org" is full of peo=
ple (including me!) who'd be willing to answer your question, but "python-d=
ev" is reserved for discussion of how to write the Python language itself, =
not how to USE python.
Now that I've chastised you for mis-using the list I'll assume that you sim=
ply didn't realize what the list was for, and that it was an honest mistake=
, so let me answer the question.
Have you ever (in any language) written something like this:
myList =3D (
a,
b,
c,
d
)
... then had to add a new item to the list:
myList =3D (
a,
b,
c,
d
e
)
... and gotten a bug? (Look very carefully, and you'll find the bug.) Well,=
that's why Python allows the
trailing comma. The only special case is a one-item tuple. Python has no go=
od way to tell a one-item
tuple apart from something that's just enclosed in parentheses (technically=
, that's because it's the
comma not the parentheses that make the tuple), so it punts and goes with a=
not-so-good way:
using a trailing comma makes it a one-item tuple. That's the only time the =
trailing comma ever matters;
otherwise it's completely optional and used for cosmetic (and typo-avoidanc=
e) reasons only.
-- Michael Chermside
This email may contain confidential or privileged information. If you belie=
ve you have received the message in error, please notify the sender and del=
ete the message without copying or disclosing it.