Python __irshift__() Magic Method

Syntax object.__irshift__(self, other) The Python __irshift__() magic method implements in-place bitwise right-shift operation x >>= y that calculates the right-shift operation x >> y, and assigns the result to the first operands variable x. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to the first … Read more

Python __ilshift__() Magic Method

Syntax object.__ilshift__(self, other) The Python __ilshift__() magic method implements in-place bitwise left-shift operation x <<= y that calculates the left-shift operation x << y, and assigns the result to the first operands variable x. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to the first … Read more

Python __imatmul__() Magic Method

Syntax object.__imatmul__(self, other) The Python __imatmul__() magic method implements in-place matrix multiplication x @= y that calculates the matrix multiplication of the two operands and assigns the result to the left operand. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to the first operand. When … Read more

Python __imul__() Magic Method

Syntax object.__imul__(self, other) The Python __imul__() magic method implements in-place multiplication x *= y that multiplies the operands with each other and assigns the result to the left operand. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to the first operand. When you call x … Read more

Python __isub__() Magic Method

Syntax object.__isub__(self, other) The Python __isub__() magic method implements in-place subtraction x -= y that subtracts the operands from each other and assigns the result to the left operand. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to the first operand. When you call x … Read more

Python __iadd__() Magic Method

Syntax object.__iadd__(self, other) The Python __iadd__() magic method implements in-place addition x += y that adds together the operands and assigns the result to the left operand. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to the first operand. When you call x += y, … Read more

Python __rrshift__() Magic Method

Syntax object.__rrshift__(self, other) The Python __rrshift__() method implements the reverse bitwise right-shift operation with reflected, swapped operands. So, when you call x >> y, Python attempts to call x.__rshift__(y). If the method is not implemented, Python attempts to call y.__rrshift__(x) on the right operand and if this isn’t implemented either, it raises a TypeError. The … Read more

Python __rlshift__() Magic Method

Syntax object.__rlshift__(self, other) The Python __rlshift__() method implements the reverse bitwise left-shift operation with reflected, swapped operands. So, when you call x << y, Python attempts to call x.__lshift__(y). If the method is not implemented, Python attempts to call y.__rlshift__(x) on the right operand and if this isn’t implemented either, it raises a TypeError. The … Read more

Python __rpow__() Magic Method

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

Python __rdivmod__() Magic Method

Syntax object.__rdivmod__(self, other) The Python __rdivmod__() method implements the divmod() built-in function with reflected, swapped operands. So, when you call divmod(x, y), Python attempts to call x.__divmod__(y). If the method is not implemented, Python attempts to call __rdivmod__ on the right operand. Only if this isn’t implemented either, it raises a TypeError. We call this … Read more