Operators

^ — Bitwise XOR and symmetric difference

For integers, sets a bit when the corresponding input bits differ. For sets, returns elements occurring in exactly one operand. Two bool values produce a bool. XOR is not exponentiation (use **). Both operands are evaluated; custom classes implement __xor__ and __rxor__. Its precedence is between & and |.

Formal Syntax & Structure

python syntaxpython
left ^ right

Parameters & Attributes

NameTypeDescription
leftint, set or supporting objectFirst operand; its type participates in operation selection.
rightcompatible operandSecond operand; supported values depend on the operand types.

Return Value

object

Result selected by the operand types and their operation implementations.

Working Example

Example Snippetpython
print(0b1100 ^ 0b1010)print(True ^ True)print(sorted({1, 2} ^ {2, 3}))
Python Reference