I am trying to write a boolean expression in Python, but it appears Python can only do XOR expressions with bit operations.
What would be the best way to go about writing this expression in Python without the XOR operator.
(A ^ B ^ C ^ D) U ((B U C U D)' XOR A)
if (A and B and C and D) or ((A and not (B or C or D)) or (not A and (B and C and D))):
Just use the bitwise
^ operator. Python's booleans return a boolean when
>>> True ^ True False >>> True ^ False True
or operators exist primarily to support short-circuiting, but XOR can't short-circuit.
>>> True != True False >>> True != False True
but that doesn't do what you want when chained with more arguments:
>>> True != True != True False