Why don't we need self reference when we use super().__init__?(such as line 9 down below)
class labourers():
def __init__(self,name,department,salary):
self.name = name
self.department = department
self.salary = salary
class managers(labourers):
def __init__(self,name,department,salary,numberofpeople):
super().__init__(name,department,salary)
self.numberofpeople = numberofpeople
Super's functionality in this case is implemented in the CPython parser. See PEP 3135
Replacing the old usage of super, calls to the next class in the MRO (method resolution order) can be made without explicitly passing the class object (although doing so will still be supported). Every function will have a cell named __class__ that contains the class object that the function is defined in.
The new syntax:
super()is equivalent to:
super(__class__, <firstarg>)[...]
While super is not a reserved word, the parser recognizes the use of super in a method definition and only passes in the __class__ cell when this is found. Thus, calling a global alias of super without arguments will not necessarily work.
Emphasis added.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With