[Tutor] super() vs. explicitly calling base class?
boB Stepp
robertvstepp at gmail.com
Sat Sep 21 00:47:10 EDT 2019
Python 3.7.4 on Linux Mint
Assumption: I have only TWO classes (Not concerned about 3+ class
inheritance scenario), Base and Child. Is there any advantage to
using super() over explicitly calling Base from within Child? My
following trivial example does not suggest any difference:
>>> class Base:
def __init__(self):
print("This is the Base class!")
>>> class Child(Base):
def __init__(self):
print("This is the Child class!")
def call_base(self):
print("About to call the Base class with super!")
super().__init__()
print("Now explicitly calling the Base class!")
Base.__init__(self)
>>> a = Base()
This is the Base class!
>>> b = Child()
This is the Child class!
>>> b.call_base()
About to call the Base class with super!
This is the Base class!
Now explicitly calling the Base class!
This is the Base class!
--
boB
More information about the Tutor
mailing list