ways to declare empty set variable

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Feb 12 21:30:38 EST 2008


George Sakkis <george.sakkis 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.

-- 
 \       “Imagine a world without hypothetical situations.” —anonymous |
  `\                                                                   |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list