comparing booleans

Erik Max Francis max at alcyone.com
Wed Jan 28 19:17:22 EST 2004


Gerrit Holl wrote:

> is it proper to compare booleans? It is possible, of course, because
> they're compatible with numbers, but booleans aren't truly numbers.
> I'm
> tempted to write:
> 
>     return cmp(self.extends, other.extends)

Even if you're seriously worried about the correctness of comparing
Booleans, you can always explicitly turn them into integers:

	return cmp(int(self.extends), int(other.extends))

> (Hmm, makes me wonder, for booleans, are != and ^ equal?)

Easily checked:

>>> for x in (True, False):
...  for y in (True, False):
...   print x, y, x != y, x ^ y 
... 
True True False False
True False True True
False True True True
False False False False

-- 
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Weakness of attitude becomes weakness of character.
    -- Albert Einstein



More information about the Python-list mailing list