Python complexassigns values to realand imagin __new__.
__new__runs before __init__and is responsible for creating the object. The implementation (taking into account myComplexand complex) is as follows:
myComplex("1 1")
myComplex.__new__(cls, inp)
complex.__new__(cls, real, imag)
myComplex.__init__(self, inp)
(No complex.__init__, since it myComplex.__init__does not cause it)
, "1 2" __init__.
__new__:
class myComplex(complex):
def __new__(cls, inp):
real, imag = inp.split()
return super(myComplex, cls).__new__(cls, float(real), float(imag))