missing 'xor' Boolean operator
Terry Reedy
tjreedy at udel.edu
Sat Jul 25 13:30:54 EDT 2009
Albert van der Horst wrote:
> Remains whether we need an xor that only works and requires that
> both operands are booleans. That one we have already!
> It is called != .
>
> (a!=b)!=c
> and
> a!=(b!=c)
>
> are the same for booleans, so can indeed be expressed
> a!=b!=c (associativy of xor)
Not in Python
>>> a,b,c = True, False, True
>>> (a!=b)!=c
False
>>> a!=(b!=c)
False
>>> a!=b!=c
True
>>> (a!=b) and (b!=c)
True
In Math and Python, a<b<c means a<b and b<c, not (a<b)<c or a<(b<c).
!= is a comparison operator like <, not an arithmetic operator like +
(or logical xor). If one has 0/1 or True/False values, we have
arithmetic xor already, ^, which works as expected.
>>> (a^b)^c
False
>>> a^b^c
False
Terry Jan Reedy
More information about the Python-list
mailing list