ways to declare empty set variable

George Sakkis george.sakkis at gmail.com
Tue Feb 12 21:15:42 EST 2008


On Feb 12, 7:02 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> Steve Holden <st... at holdenweb.com> writes:
> > Ben Finney wrote:
> > [...]
>
> > > Note that '()' is syntactically null. Parentheses don't declare a
> > > tuple literal, commas do. Parentheses are for grouping within
> > > expressions, not specifying type.
>
> > Tell that to the interpreter:
>
> > >>> type(())
> > <type 'tuple'>
> > >>> tuple() is ()
> > True
>
> Well, knock me down with a kipper.
>
> That makes it even more a violation of principle-of-least-astonishment
> that the '(foo)' form doesn't give a one-element tuple literal.

The reason being, of course, that in this case '(1+2) * 3' would give
a result several orders of magnitude more astonishing, so it's well
worth the slight inconvenience of one-element tuples.

George



More information about the Python-list mailing list