Back
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()
@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/
In Python 3, we can call it like this:
class ChildB(Base): def __init__(self): super().__init__()
class ChildB(Base):
def __init__(self):
super().__init__()
You can use the following video tutorials to clear all your doubts:-
31k questions
32.8k answers
501 comments
693 users