Join my Asyncio (Python) course on Udemy for free 👀

Python XOR (^) operator

May 15, 2022  ‐ 1 min read

The XOR operator (^) is one of the bitwise operators in Python. Bitwise operators allow for logical operation in your Python code.

XOR stands for "exclusive or" here, the "exclusive or" logical operation only evaluates to true if the two given inputs differ.

Thus, if one is true and one is false. This is not to be confused with the bitwise OR operator (|), which evaluates to true if one of the two inputs or both are true.

The truth table of the XOR operator in Python looks as follows:

True ^ True   # => False
True ^ False  # => True
False ^ True  # => True
False ^ False # => False