Annoying behaviour of the != operator
apardon at forel.vub.ac.be
Thu Jun 9 12:42:34 CEST 2005
Op 2005-06-08, Mahesh schreef <sutram at gmail.com>:
> No, why should Python assume that if you use != without supplying a
> __ne__ that this is what you want? Without direction it will compare
> the two objects which is the default behavior.
> So, s != t is True because the ids of the two objects are different.
> The same applies to, for example s > t and s < t. Do you want Python to
> be smart and deduce that you want to compare one variable within the
> object if you don't create __gt__ and __lt__? I do not want Python to
> do that.
Python is already smart. It deduces what you want with the += operator
even if you haven't defined an __iadd__ method. If python can be smart
with that, I don't see python being smart with !=.
More information about the Python-list