missing 'xor' Boolean operator

Jean-Michel Pichavant jeanmichel at sequans.com
Wed Jul 15 11:15:47 EDT 2009


Christian Heimes wrote:
> Chris Rebert wrote:
>   
>> Using the xor bitwise operator is also an option:
>> bool(x) ^ bool(y)
>>     
>
> I prefer something like:
>
>     bool(a) + bool(b) == 1
>
> It works even for multiple tests (super xor):
>
>   if bool(a) + bool(b) + bool(c) + bool(d) != 1:
>       raise ValueError("Exactly one of a, b, c and d must be true")
>
> Christian
>
>   
While everyone's trying to tell the OP how to workaround the missing xor 
operator, nobody answered the question "why is there no xor operator ?".

If the question was "Why is there no 'or' operator ?", would "because A 
or B <=> not(not A and not B)" be a proper answer ?

JM




More information about the Python-list mailing list