Proposed PEP for a Conditional Expression
Greg Ewing
greg at cosc.canterbury.ac.nz
Thu Sep 13 18:59:57 EDT 2001
Ken Seehof wrote:
>
> Also, I would propose that ... else None should be implicit.
> >>> print 'eeek' if pi == 3
> None
>
> But ... people could easily be confused and misinterpret the syntax as:
> <statement> if <cond> [ else <statement> ]
That's a good argument for making the else mandatory.
It's less easy to misinterpret
print 'eeek' if pi == 3 else None
It would be even clearer if parentheses were required:
print ('eeek' if pi == 3 else None)
So I suggest that parentheses always be required around
if..else expressions. That would clear up any potential
confusion in list comprehensions, and anywhere else that
it might occur.
--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list