[Python-3000] Set literal

Nick Coghlan ncoghlan at gmail.com
Sat Jan 26 16:26:23 CET 2008


Terry Reedy wrote:
> "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

No parens needed, unless the comma would be interpreted as meaning 
something else if the parens were left out (function argument separator, 
name separator in a 2.x series except clause, item separator in a 
surrounding tuple/list/dict definition, etc), or if the first expression 
would be overinclusive without them (e.g. string formatting with %). A 
lot of the time I find it easier to just include the parentheses instead 
of worrying about it (they're kind of like yield expressions that way...).

Anyway, for the kind of stylistic comparison I was talking about in the 
previous post, I think it is useful to think of the parentheses as part 
of the tuple syntax (because that's the way they are often written), 
even though that isn't completely correct in terms of the language's 
grammar.

We've veered pretty far from the original topic now though, so it would 
probably be best to drop the mailing list from any further discussion :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list