Annoying behaviour of the != operator

Rocco Moretti roccomoretti at hotpop.com
Wed Jun 8 16:01:57 EDT 2005


Matt Warden wrote:
> Jordan,
> 
> On 8 Jun 2005 11:44:43 -0700, Jordan Rastrick
> <jrastrick at student.usyd.edu.au> wrote:
> 
>>But I explicitly provided a method to test equality. And look at the
>>plain english meaning of the term "Not equals" I think its pretty
>>reasonable
> 
> 
> Indeed. Furthermore, it seems quite silly that these would be different:
> 
> a != b
> not (a == b)

It's only "silly" if one sticks to strict Boolean semantics or 
implicitly assumes the law of the excluded middle 
(http://en.wikipedia.org/wiki/Excluded_middle), the principle of 
bivalence (http://en.wikipedia.org/wiki/Principle_of_bivalence), or the 
law of noncontradiction 
(http://en.wikipedia.org/wiki/Law_of_non-contradiction). Despite "law" 
status, it is possible (and useful) to imagine situations where they 
don't hold. (A'la non-euclidlean geometry).

The main problem is that Python is trying to stick at least three 
different concepts onto the same set of operators: equivalence (are 
these two objects the same?), ordering (in a sorted list, which comes 
first?), and mathematical "size". This gives the wacky world where 
"[(1,2), (3,4)].sort()" works, whereas "[1+2j, 3+4j].sort()" doesn't.

Luckily another related concept, identity, has already been separated 
out (the 'is' operator). It would be nice (but I'm not hoding my breath) 
if the complete issue gets resolved with Python 3000.



More information about the Python-list mailing list