all Python 3operatorfunction
operator.ixor
in-place
In-place bitwise XOR: a ^= b.
Syntax
operator.ixor(a, b)
For a set it mutates in place into the symmetric difference: ixor({1, 2}, {2, 3}) gives {1, 3}. For ints assign the result; this toggles bits: flags = ixor(flags, MASK) flips exactly the bits set in the mask.
Examples
import operator
from functools import reduce
print(operator.ixor(5, 3)) # → 6
print(reduce(operator.ixor, [4, 7, 4, 7, 9])) # → 9
flags = 0b1010
print(bin(operator.ixor(flags, 0b0010))) # → 0b1000
s = {1, 2, 3}
print(sorted(operator.ixor(s, {3, 4}))) # → [1, 2, 4]
print(sorted(s)) # → [1, 2, 4]
See also
Open in the full glossarydocs.python.orgReport an inaccuracy