I am not sure what to call this so please bear with me.
Right now I have a class / object where I overloaded the multiplication operator def __mul__(self, secondthing):and so if I do myObject * 4 it knows what to do with it.
But it doesn't know what to do if I do 4 * myObject, the other way around.
You could implement __rmul__.
These methods are called to implement the binary arithmetic operations (+, -, *, /, %, divmod(), pow(), **, <<, >>, &, ^, |) with reflected (swapped) operands. These functions are only called if the left operand does not support the corresponding operation and the operands are of different types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With