[Python-ideas] XOR

Lie Ryan lie.1296 at gmail.com
Thu Nov 26 23:00:27 CET 2009


Alexander Belopolsky wrote:
> On Tue, Oct 27, 2009 at 6:41 PM, Sturla Molden <sturla at molden.no> wrote:
>> Why does Python have a bitwise but not a logical xor operator?
> 
> .. because it does:  !=
> 
>>>> True != True
> False
>>>> True != False
> True
>>>> False != False
> False
> 
> In 2.x you can even use <> if you like syntactic sugar. :-)
> 
> On arbitrary types a xor b is arguably bool(a) != bool(b) rather than
> simple a != b, but it is rare enough to warrant additional syntax.
> 
> I thought I've seen this answered in an FAQ list somewhere.

I've seen this in Java. But the field is different there, with no 
operator overloading != is always be equivalent with logical XOR. I'm +0 
on the proposal, for being very rarely needed.




More information about the Python-ideas mailing list