if - else
John J. Lee
jjl at pobox.com
Thu Nov 27 18:16:28 EST 2003
Jeff Wagner <JWagner at hotmail.com> writes:
> On Thu, 27 Nov 2003 22:28:29 GMT, Christopher Koppler <klapotec at chello.at> wrotf:
[...]
> >It does assignment (=) instead of comparison (==) in the condition,
> >which is illegal in Python.
>
> Yikes, I didn't even notice the = instead of the == ... thanks.
That's why it's illegal :-)
In C, this has caused endless bugs. It's the reason experienced C
coders write stuff like:
if (10 == sum) {...}
rather than
if (sum == 10) {...}
-- the first won't compile if you accidentally write
if (10 = sum) {...}
Unfortunately, that doesn't get you out of all the trouble this
causes.
What would be nice in Python, I think, is an assignment operator for
assignment expressions that can't be mistaken or mistyped for equality
comparison. One trivial but annoyingly real problem is, ASCII has no
decent arrow symbol -- and unicode saturation is a long way off.
Guido seems to have no interest in the idea, anyway.
John
More information about the Python-list
mailing list