ways to declare empty set variable
Ben Finney
bignose+hates-spam at benfinney.id.au
Tue Feb 12 19:09:22 EST 2008
bearophileHUGS at lycos.com writes:
> 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.
Now, that one I *am* sure of. Generator literals do not require the
parens at all. However, the syntax of where the generator literal
*appears* can make it necessary to explicitly group the expression
using parens.
>>> import string
>>> list(char for char in string.digits)
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>>> char for char in string.digits
File "<stdin>", line 1
char for char in string.digits
^
SyntaxError: invalid syntax
So, it's not that parens are "used for generator literals". It's that
parens can be used to make grouping explicit where the syntax would
otherwise be ambiguous.
--
\ "If you're a horse, and someone gets on you, and falls off, and |
`\ then gets right back on you, I think you should buck him off |
_o__) right away." -- Jack Handey |
Ben Finney
More information about the Python-list
mailing list