[Python-3000] Set literal
tjreedy at udel.edu
Sat Jan 26 09:21:53 CET 2008
"Nick Coghlan" <ncoghlan at gmail.com> wrote in message
news:479A08BB.6010101 at gmail.com...
| More completely:
| () # empty tuple
| (1,) # 1 item tuple
| (1,2) # 2 item tuple
1, # 1 item tuple, no parens needed, trailing comma mandatory
1,2 # 2 item tuple, no parens needed
1,2, # 2 item tuple with optional trailing comma
The anomaly is the need for parens to denote an empty tuple since
it is otherwise hard to tell a tuple nothing from a nothing nothing. The
alternative would have been to use a bare trailing , ... but I guess Guido
thought 'a = ,' and 'a == ,' would look odder than the current form,
although it would have avoided the implication that parens rather than
commas make tuples (other than the empty one).
| - 1-tuples require a trailing comma to differentiate them from the use
| of parentheses for mere expression grouping.
1-tuples require the trailing comma in order to have at least one around to
differentiate them from bare expressions. Except for empty tuples, parens
only need be added if they are indeed needed for expression grouping (which
they often are because of precedence).
More information about the Python-3000