+ 2
inheritance of constructors
class A(object): def __init__(self): print (1) class B(A): def __init__(self): super(A, self).__init__() print (2) B() Why print just 2?
4 ответов
+ 3
Hmmm, maybe because A has no Parent?
+ 2
The super-Function didn't need any Arguments. Just change the line:
super().__init__()
+ 1
Yes, exectly! You are right!
0
It's properly. Yes, but its optional in python3 and if I write super(A, self), there is no error.
And I tried in python2.7 to lainch the code (the same code, but without the parentheses after print) and I have experimented and I have the same results: just 2
i know: if i write super(B, self) instead super(A, self), i'll get all right: 12. But I do not know, what is the different beetwen A and B in super-function?
why super(A,self) do not call the __init__ of the parent?