Learning Scientific Programming with Python (2nd edition)

P2.2.1: The XOR operator

Question P2.2.1

There is no exclusive-or operator provided "out of the box" by Python, but one can be constructed from the existing operators. Find two different ways of doing this. (The XOR truth table is provided below).

PQP xor Q
TrueTrueFalse
FalseTrueTrue
TrueFalseTrue
FalseFalseFalse