#!/usr/bin/pythonclass Parent(object): # define parent classparentAttr = 100def __init__(self):print "Calling parent constructor"def parentMethod(self):print 'Calling parent method'def setAttr(self, attr):Parent.parentAttr = attrdef getAttr(self):print "Parent attribute :", Parent.parentAttrclass Child(Parent): # define child classdef __init__(self):print "Calling child constructor"def childMethod(self):print 'Calling child method'c = Child() # instance of child
I have called created an instance of the Child class here.It doesn't seem to call the constructor of the parent class.The output looks like shown below.
Calling child constructor
In C++ for example when you call the constructor of a derived class the base class constructor get called first.Why is this not happening in Python?