ways to declare empty set variable
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Tue Feb 12 18:48:45 EST 2008
Ben Finney:
> I often use these myself. They're slightly more explicit, which can
> help when I want the reader not to have to think too much, and they're
> not particularly verbose because the names are well-chosen and short.
I'd like "list" be called "array" ;-)
> Note that '()' is syntactically null. Parentheses don't declare a
> tuple literal, commas do.
() is the literal for the empty tuple:
>>> t = ()
>>> type(t)
<type 'tuple'>
>>> (1, 2)[0:0]
()
>Parentheses are for grouping within expressions, not specifying type.<
I know, but I prefer Fortress in that regard, where each container has
its specific delimiter(s). In Python ( ) denote:
- expression grouping
- they are very often used to denote tuples (despite being necessary
only for the empty one)
- generators (x for x in ...).
The Boo language shows that () aren't that necessary for the
generators.
> I thought you said above that you preferred 'set()' for an empty set?
> I'm not sure what it is you're saying now.
Your language isn't my first one, and for me sometimes it's not easy
to express complex things :-) I can try again. Here are syntax pairs
(for empty dict && empty set) sorted from the (IMHO) the best one to
the worst one:
{:} && {}
dict() && set()
{} && set()
{} && {/}
> I think the harm done by trying to change it would be more
> than the harm done by leaving it in.
I agree.
Bye,
bearophile
More information about the Python-list
mailing list