ways to declare empty set variable

George Sakkis george.sakkis at gmail.com
Tue Feb 12 23:36:02 EST 2008


On Feb 12, 9:30 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> George Sakkis <george.sak... at gmail.com> writes:
> > On Feb 12, 7:02 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
> > wrote:
> > > 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,
>
> Yes, of course.
>
> > so it's well worth the slight inconvenience of one-element tuples.
>
> I didn't make it clear, but my expected solution to this is that '()'
> should not create an empty tuple (as I was clearly assuming earlier in
> this thread). An empty set can still be created with 'set()'.
>
> That way, it becomes clearer that it's the comma separator, not the
> parens, that create a tuple literal. With '()' creating an empty tuple
> literal, and '(foo, bar)' creating a two-element tuple literal, it
> remains that much harder to remember that '(foo)' does *not* create a
> tuple.

*shrug* I've never been bitten by this. From a purist POV I see your
point but I guess it's one of the things you learn when you first pick
up Python and never have to think again.

George



More information about the Python-list mailing list