Special Method Protocols
__rlshift__() — reflected numeric protocol
Implement reflected left shift (<<) when the other operand declines the operation or reflected subclass priority applies. The other operand is logically on the left; preserve operand order. Return NotImplemented for unsupported types.
Formal Syntax & Structure
python syntaxpython
def __rlshift__(self, other):Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| other | object | Other operand. |
Return Value
object | NotImplementedType
Operation result, or NotImplemented to decline.
Working Example
Example Snippetpython
class Number: def __init__(self, value): self.value = value def __rlshift__(self, other): if not isinstance(other, int): return NotImplemented return other << self.valueprint(3 << Number(2))