When does super() need arguments to function correctly?

3726 views python
9

EX:

class Parent:

    def name(self):
        print("This is the parent method name()")


class Child(Parent):

    def name(self):
        super(Child, self).name()
        super().name()


dad = Parent()
son = Child()

dad.name()
son.name()


Output:
This is the parent method name()
This is the parent method name()
This is the parent method name()

I am confused as to why this works correctly in both cases, and I would like to know when I would have to use the super(Child, self).name() form in my code. Any help is greatly appreciated!

answered question

It has been made easier in python 3 as you don't need to insert any arguments for the super(). Try reading this thread.

That thread really helped. Don't know why I couldn't find it before. Thank you!

1 Answer

4

Easy:
Python 2.* - Arguments are always required.
Python 3.* - Arguments are never required.

posted this

Have an answer?

JD

Please login first before posting an answer.