For review: PEP 308 - If-then-else expression
John Hazen
python-list at hazen.net
Sun Feb 9 04:05:57 EST 2003
I'm a python newbie (written ~100 lines of python and read c.l.py for a couple
of weeks), and I wanted to weigh in on the clarity of the proposal.
I found it intuitive and easy to understand. I like the order that Guido has
proposed, and disagree with those who claim it doesn't read luft-to-right.
It's just the way I would say it in english:
My activity is "eating" if I'm hungry, otherwise I'll be "reading c.l.py".
myActivity = "eating" if hungry else "reading c.l.py"
I want to caution against making the else clause optional, as it blurs the
distinction between the conditional _operator_ and the conditional _statement_.
Most of you seem to interpret
>>> activity = "eating" if hungry
to mean:
>>> activity = "eating" if hungry else None
(obvious default if you know it's conditional _evaluation_)
But, as a future former perl programmer, to me this means:
>>> activity = "eating" if hungry else activity
(default if you think it's conditional _execution_; the variable
retains its former value.)
I'm in favor of the PEP.
John
--
John Hazen
john at my domain (see headers)
More information about the Python-list
mailing list