Object Orientation

Python __rmatmul__() Magic Method

Syntax object.__rmatmul__(self, other) The Python __rmatmul__() method implements the reverse matrix multiplication @ operation with reflected, swapped operands. So, when you call x @ y, Python attempts to call x.__matmul__(y). If the method is not implemented, Python attempts to call __rmatmul__ on the right operand and if this isn’t implemented either, it raises a TypeError. …

Python __rmatmul__() Magic Method Read More »

Python __rand__() Magic Method

Syntax object.__rand__(self, other) The Python __rand__() method implements the reverse Bitwise AND * operation with reflected, swapped operands. So, when you call x * y, Python attempts to call x.__and__(y). If the method is not implemented, Python attempts to call __rand__ on the right operand and if this isn’t implemented either, it raises a TypeError. …

Python __rand__() Magic Method Read More »

Python __rmul__() Magic Method

Syntax object.__rmul__(self, other) The Python __rmul__() method implements the reverse multiplication operation that is multiplication with reflected, swapped operands. So, when you call x * y, Python attempts to call x.__mul__(y). Only if the method is not implemented on the left operand, Python attempts to call __rmul__ on the right operand and if this isn’t …

Python __rmul__() Magic Method Read More »

Python __rsub__() Magic Method

Syntax object.__rsub__(self, other) The Python __rsub__() method implements the reverse subtraction operation that is subtraction with reflected, swapped operands. So, when you call x – y, Python attempts to call x.__sub__(y). Only if the method is not implemented on the left operand, Python attempts to call __rsub__ on the right operand and if this isn’t …

Python __rsub__() Magic Method Read More »

Python __radd__() Magic Method

Syntax object.__radd__(self, other) The Python __radd__() method implements the reverse addition operation that is addition with reflected, swapped operands. So, when you call x + y, Python attempts to call x.__add__(y). Only if the method is not implemented on the left operrand, Python attempts to call __radd__ on the right operand and if this isn’t …

Python __radd__() Magic Method Read More »

Python __rxor__() Magic Method

Syntax object.__rxor__(self, other) The Python __rxor__() method implements the reverse Bitwise XOR ^ operation with reflected, swapped operands. So, when you call x ^ y, Python attempts to call x.__xor__(y). If the method is not implemented, Python attempts to call __rxor__ on the right operand and if this isn’t implemented either, it raises a TypeError. …

Python __rxor__() Magic Method Read More »

Python __xor__() Magic Method

Syntax object.__xor__(self, other) The Python __xor__() method implements the built-in Bitwise XOR ^ operation. So, when you cal x ^ y, Python attempts to call x.__xor__(y). If the method is not implemented, Python first attempts to call __rxor__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call this …

Python __xor__() Magic Method Read More »

Python __or__() Magic Method

Syntax object.__or__(self, other) The Python __or__() method implements the built-in Bitwise OR | operation. So, when you cal x | y, Python attempts to call x.__or__(y). If the method is not implemented, Python first attempts to call __ror__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call this …

Python __or__() Magic Method Read More »

Python __and__() Magic Method

Syntax object.__and__(self, other) The Python __and__() method implements the built-in Bitwise AND & operation. So, when you cal x & y, Python attempts to call x.__and__(y). If the method is not implemented, Python first attempts to call __rand__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call this …

Python __and__() Magic Method Read More »

Python __rshift__() Magic Method

Syntax object.__rshift__(self, other) The Python __rshift__() method implements the built-in >> operation. So, when you cal x >> y, Python attempts to call x.__rshift__(y). If the method is not implemented, Python first attempts to call __rrshift__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call this a “Dunder …

Python __rshift__() Magic Method Read More »

Python __lshift__() Magic Method

Syntax object.__lshift__(self, other) The Python __lshift__() method implements the built-in << operation. So, when you cal x << y, Python attempts to call x.__lshift__(y). If the method is not implemented, Python first attempts to call __rlshift__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call this a “Dunder …

Python __lshift__() Magic Method Read More »

Python __pow__() Magic Method

Syntax object.__pow__(self, other) The Python __pow__() method implements the built-in exponentiation operation. So, when you call pow(a, b) or a ** b, Python attempts to call x.__pow__(y). If the method is not implemented, Python first attempts to call __rpow__ on the right operand and if this isn’t implemented either, it raises a TypeError. We call …

Python __pow__() Magic Method Read More »