Why = = (and not just =)
Hans Nowak
hans at zephyrfalcon.org
Mon Oct 20 00:08:51 EDT 2003
Joe Green wrote:
> Sorry, I cant help aking stupid questions:
>
> I understand why we need = = in C, but why in Python (or Java),
> surely if you write
> if a=b: pass # syntax error
> it could not possibly mean anything other than what I intended
> (which was of course if a = = b:) ?
But it leads to ambiguities in other situations... a = b = c, for example.
Interestingly, very old versions of Python did use = as the equality operator.
See Misc/HISTORY in the source distribution:
New features in 0.9.6:
[...]
- '==' is now the only equality operator; "../demo/scripts/eqfix.py" is
a script that fixes old Python modules
Release 0.9.3 (never made available outside CWI)
[...]
- C comparison operators: == != (the old = and <> remain valid).
ABC apparently used = as well, and <> for inequality. I'm assuming this is
where the first versions of Python got it from. Judging from the history file,
= was soon replaced by ==; <> is still valid today, but deprecated in favor of !=.
Cheers,
--
Hans (hans at zephyrfalcon.org)
http://zephyrfalcon.org/
More information about the Python-list
mailing list