PEP 308: Pep Update

Bernhard Herzog bh at intevation.de
Fri Feb 28 06:26:37 EST 2003


"Greg Ewing (using news.cis.dfn.de)" <me at privacy.net> writes:

> > 3) reuses existing keywords (if, else)
> 
> A minor correction: "else" is not currently a reserved

AFAIK, it has always been a reserved word. How could it not be? The
colon it's usually followed by is not part of the keyword according to
the grammar:

if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]

The other productions that include else are defined similarly.

I also can't use it as a variable name:
>>> else = 1
  File "<string>", line 1
    else = 1
       ^
SyntaxError: invalid syntax

And it's listed as a keyword in the keyword module:
>>> import keyword
>>> keyword.kwlist
['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif',
'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if',
'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise',
'return', 'try', 'while', 'yield']

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/





More information about the Python-list mailing list