It shows error-Super takes atleast one argument?Why is it?It's the same code as written by sir(I am using Python 2)

class school:
def init(self,name,age):
self.name=name
self.age=age
print(’(Initialized Teacher:{})’.format(self.name))

def tell(self):
    print('Name: "{}" Age: "{}"'.format(self.name,self.age)+" ")

class teacher(school):
def init(self,name,age,salary):
super().init(name,age)
self.salary=salary
print(’(Initialized teacher: {})’.format(self.name))

def tell(self):
    super().tell()
    print('Salary: "{:d}"'.format(self.salary))

t=teacher(‘ujjwal’,40,3000)
t.tell()

Hi @Subrat

First of all, stop using Python 2. It is very out-dated and not even supported with updates now. Upgrade to Python 3.x asap.

Secondly, this code snippet shows how to handle this issue:

class Foo(object):
    def __init__(self):
        pass

class Bar(Foo):
    def __init__(self):
        super().__init__()

Bar()

The workaround to make it work would be:

class Foo(object):
    def __init__(self):
        pass

class Bar(Foo):
    def __init__(self):
        super(Bar, self).__init__()

Bar()
1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

The reason to use super is so that child classes that may be using cooperative multiple inheritance will call the correct next parent class function in the Method Resolution Order (MRO).

In Python 3, we can call it like this:

class ChildB(Base):
    def __init__(self):
        super().__init__()

In Python 2, you were required to call super like this with the defining class’s name and self, but you’ll avoid this from now on because it’s redundant, slower (due to the name lookups), and more verbose (so update your Python if you haven’t already!):

super(ChildB, self).__init__()

Without super, you are limited in your ability to use multiple inheritance because you hard-wire the next parent’s call:

Base.__init__(self) # Avoid this.