So I am making a class called Complex which a representation of imaginary numbers (I know python has its own, but i want to make one myself). Thing is I want to construct an add method that supports addition of complex numbers as well as integers. So:
a = Complex(2, 4) + Complex(1, 1)
b = Complex(0, 3) + 3
c = 2 + Complex(4, 5)
should all be supported. As I understand,
object1 + object2
is the syntactic-sugar-equivalent of
object1.__add__(object2)
First and second examples are fine, but how do I get my class to support addition on the form INTEGER + COMPLEX? Do I have to override integer __add__method, if so; how do I do that, and is there another way?