Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок+ 2
Python is a
Why does the following print only "2"? Doesn't it call A's __init__ method? I expected it to print "1" and then "2" since I thought A's __init__ would be called. class A: def __init__(self): print(1) class B(A): def __init__(self): super(A, self).__init__() print(2) obj = B()
3 ответов
+ 3
Dublicating question..?
anyways, .. for more details.. see answers..
https://www.sololearn.com/discuss/2814302/?ref=app
+ 2
This is interesting. super(B, self) is kind of same as parameterless super() and gives the expected output.
class A:
def __init__(self):
print(1)
class B(A):
def __init__(self):
super().__init__()
print(2)
obj = B()
But what happens if we use super(A, self) inside class B, like in your example? can we do that ?
+ 1
this is a great day of the Answering Reality.