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 ^ rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | int, set or supporting object | First operand; its type participates in operation selection. |
| right | compatible operand | Second 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}))