ways to declare empty set variable
george.sakkis at gmail.com
Wed Feb 13 03:15:42 CET 2008
On Feb 12, 7:02 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
> 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.
More information about the Python-list