Special Method Protocols
__ixor__() — in place numeric protocol
Handle augmented assignment with ^= for bitwise exclusive-or. The hook may mutate the receiver or return a different object; assignment binds the returned result. If absent or returning NotImplemented, Python tries the ordinary binary operation. The example intentionally mutates a wrapper.
Formal Syntax & Structure
python syntaxpython
def __ixor__(self, other):Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| other | object | Other operand. |
Return Value
object | NotImplementedType
Result assigned back to the target, or NotImplemented to decline.
Working Example
Example Snippetpython
class Number: def __init__(self, value): self.value = value def __ixor__(self, other): if not isinstance(other, int): return NotImplemented self.value = self.value ^ other return self
def apply(): x = Number(6) alias = x x ^= 3 return x.value, x is aliasprint(apply())