That is because Parent.__init__()
always requires self
.
However, super().__init__()
does not require self
because it implicitly finds the self
by MRO (Method Resolution Order). You can see the order using Class.__mro__
, as follows:
class Parent:
def __init__(self, name):
self.name = name
def printName(self):
print(self.name)
class Child(Parent):
def __init__(self, name):
Parent.__init__(self, name)
bob = Child('Bob')
print(Child.__mro__)
# (<class '__main__.Child'>, <class '__main__.Parent'>, <class 'object'>)
Here, if you use super.__init__(name)
instead of Parent.__init(self, name)
, it will find Parent
by the order.
For more information: see https://docs.python.org/3/library/functions.html#super