For review: PEP 308 - If-then-else expression

Andrew Koenig ark at research.att.com
Mon Feb 10 00:46:54 EST 2003


>> Why is extra lookahead required here?  The "if" is the first token in
>> the statement, so it can only denote an if-statement, not an
>> if-expression.  

Roman> In Python, expression is a standalone statement. So in case of 

Roman> if expr1: expr2 else: expr3

Roman> the parser will notice the difference only at "else".

I'm proposing that the parser should decide when it sees the "if" that
it is parsing an if-statement and rule out the possibility that it is
parsing an expression that is also a statement.






More information about the Python-list mailing list