Operators

^= — Bitwise XOR assignment

Update integer bits that differ or compute a mutable set’s symmetric difference. For sets, existing elements shared with the right operand are removed and previously absent elements are inserted. An alias observes in-place set changes. The __ixor__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.

Formal Syntax & Structure

python syntaxpython
target ^= expression

Parameters & Attributes

NameTypeDescription
targetobjectExisting assignable name, attribute, item or slice; its current value participates in the operation.
rightinteger or compatible setValue used as the right operand of the operation.

Working Example

Example Snippetpython
flags = 0b1100flags ^= 0b0101selected = {1, 2}alias = selectedselected ^= {2, 3}print(flags)print(sorted(alias))
Python Reference