Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
4 views
in Python by (3.9k points)
edited by

I am a learner and just want to know the basic concept of super().

Here in the given code I want to know the difference between the two child classes:

    class Base(object):

    def __init__(self):

    print "Base created"

    class ChildOne(Base):

    def __init__(self):

    Base.__init__(self)

    class ChildTwo(Base):

    def __init__(self):

    super(ChildTwo, self).__init__()

    ChildOne()

    ChildTwo()

2 Answers

0 votes
by (10.9k points)
edited by

@Shubham, You can avoid referring to base class explicitly using super(). Multiple-inheritance is not possible without using super().

Python also changed its syntax in version 3.0 , super()._init_() and super(ChildTwo, self)._init_() both perform the same function but the later is a bit nicer.

For more information regarding super() visit this link-https://rhettinger.wordpress.com/2011/05/26/super-considered-super/

0 votes
by (106k points)

In Python 3, we can call it like this:

class ChildB(Base):

    def __init__(self):

        super().__init__() 

You can use the following video tutorials to clear all your doubts:-

Related questions

0 votes
1 answer
asked Sep 10, 2019 in Java by Nigam (4k points)
0 votes
1 answer
asked Jul 4, 2019 in Python by Sammy (47.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...