SlideShare a Scribd company logo
1 of 4
Inheritance isthe capabilityof one classtoderive orinheritthe propertiesfromanotherclass.The benefitsof
inheritance are:
It representsreal-worldrelationshipswell.
It providesreusabilityof acode.We don’thave to write the same code againand again.Also,itallowsusto add
more featurestoa class withoutmodifyingit.
It istransitive innature,whichmeansthatif classB inheritsfromanotherclassA,thenall the subclassesof B would
automaticallyinheritfromclassA.
# A Pythonprogram to demonstrate inheritance
# Base or Superclass.Note objectinbracket.
# (Generally,objectismade ancestorof all classes)
# InPython3.x "classPerson"is
# equivalentto"classPerson(object)"
classPerson(object):
# Constructor
def __init__(self,name):
self.name=name
# To get name
def getName(self):
returnself.name
# To checkif thispersonisan employee
def isEmployee(self):
returnFalse
# InheritedorSubclass(Note Personinbracket)
classEmployee(Person):
# Here we returntrue
def isEmployee(self):
returnTrue
# Drivercode
emp= Person("Geek1") # AnObjectof Person
print(emp.getName(),emp.isEmployee())
emp= Employee("Geek2") #An Objectof Employee
print(emp.getName(),emp.isEmployee())
==============
Subclassing(Callingconstructorof parentclass)
A childclassneedstoidentifywhichclassisitsparentclass.Thiscan be done bymentioningthe parent classname in
the definitionof the childclass.
Eg: class subclass_name (superclass_name):
_ _ _
_ _ _
# Pythoncode to demonstrate howparentconstructors
# are called.
# parentclass
classPerson( object):
# __init__ isknownas the constructor
def __init__(self,name,idnumber):
self.name =name
self.idnumber=idnumber
def display(self):
print(self.name)
print(self.idnumber)
# childclass
classEmployee( Person):
def __init__(self,name,idnumber,salary,post):
self.salary=salary
self.post=post
# invokingthe __init__of the parentclass
Person.__init__(self,name,idnumber)
# creationof an objectvariable oran instance
a = Employee('Rahul',886012, 200000, "Intern")
# callingafunctionof the class Personusingitsinstance
a.display()
====
Differentformsof Inheritance:
1. Single inheritance:Whenachildclassinheritsfromonlyone parentclass,itiscalledsingle inheritance.We sawan
example above.
2. Multiple inheritance:Whenachildclassinheritsfrommultipleparentclasses,itiscalledmultiple inheritance.
Unlike Javaand like C++,Pythonsupportsmultipleinheritance.We specifyall parentclassesasacomma-separated
listinthe bracket.
# Pythonexampletoshowthe workingof multiple
# inheritance
classBase1(object):
def __init__(self):
self.str1="Geek1"
print("Base1")
classBase2(object):
def __init__(self):
self.str2="Geek2"
print("Base2")
classDerived(Base1,Base2):
def __init__(self):
# Callingconstructorsof Base1
# and Base2 classes
Base1.__init__(self)
Base2.__init__(self)
print("Derived")
def printStrs(self):
print(self.str1,self.str2)
ob = Derived()
ob.printStrs()
=======
3. Multilevel inheritance:Whenwe have achildand grandchild relationship.
# A Pythonprogramto demonstrate inheritance
# Base or Superclass.Note objectinbracket.
# (Generally,objectismade ancestorof all classes)
# InPython3.x "classPerson"is
# equivalentto"classPerson(object)"
classBase(object):
# Constructor
def __init__(self,name):
self.name=name
# To get name
def getName(self):
returnself.name
# InheritedorSubclass(Note Personinbracket)
classChild(Base):
# Constructor
def __init__(self,name,age):
Base.__init__(self,name)
self.age =age
# To get name
def getAge(self):
returnself.age
# InheritedorSubclass(Note Personinbracket)
classGrandChild(Child):
# Constructor
def __init__(self,name,age,address):
Child.__init__(self,name,age)
self.address=address
# To get address
def getAddress(self):
returnself.address
# Drivercode
g = GrandChild("Geek1",23,"Noida")
print(g.getName(), g.getAge(),g.getAddress())

More Related Content

What's hot

Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dharmisha Sharma
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsakreyi
 
Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기Taehwan kwon
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Anil Bapat
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its typesSuraj Bora
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsAjax Experience 2009
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScriptKeithMurgic
 
JDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk KönigJDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk KönigPROIDEA
 

What's hot (14)

Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++
 
C# note
C# noteC# note
C# note
 
ICPC Demo
ICPC DemoICPC Demo
ICPC Demo
 
Python master class part 1
Python master class part 1Python master class part 1
Python master class part 1
 
polymorphism
polymorphism polymorphism
polymorphism
 
PhD Dissertation
PhD DissertationPhD Dissertation
PhD Dissertation
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Python master class 2
Python master class 2Python master class 2
Python master class 2
 
Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
 
Douglas Crockford Presentation Goodparts
Douglas Crockford Presentation GoodpartsDouglas Crockford Presentation Goodparts
Douglas Crockford Presentation Goodparts
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
JDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk KönigJDD2015: Frege - how to program with pure functions - Dierk König
JDD2015: Frege - how to program with pure functions - Dierk König
 

Similar to Python inheritance

Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in pythonSantosh Verma
 
PHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptxPHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptxAtikur Rahman
 
14_inheritance.ppt
14_inheritance.ppt14_inheritance.ppt
14_inheritance.pptsundas65
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxnaeemcse
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeDhivyaa C.R
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Oop Constructor Destructors Constructor Overloading lecture 2
Oop Constructor  Destructors Constructor Overloading lecture 2Oop Constructor  Destructors Constructor Overloading lecture 2
Oop Constructor Destructors Constructor Overloading lecture 2Abbas Ajmal
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects newlykado0dles
 

Similar to Python inheritance (20)

Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
 
PHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptxPHP OOP Lecture - 03.pptx
PHP OOP Lecture - 03.pptx
 
Python lecture 8
Python lecture 8Python lecture 8
Python lecture 8
 
14_inheritance.ppt
14_inheritance.ppt14_inheritance.ppt
14_inheritance.ppt
 
Inheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptxInheritance in Java beginner to advance with examples.pptx
Inheritance in Java beginner to advance with examples.pptx
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Only oop
Only oopOnly oop
Only oop
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
OOPS.pptx
OOPS.pptxOOPS.pptx
OOPS.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Unit 3 notes.pdf
Unit 3 notes.pdfUnit 3 notes.pdf
Unit 3 notes.pdf
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 
Python advance
Python advancePython advance
Python advance
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Oop Constructor Destructors Constructor Overloading lecture 2
Oop Constructor  Destructors Constructor Overloading lecture 2Oop Constructor  Destructors Constructor Overloading lecture 2
Oop Constructor Destructors Constructor Overloading lecture 2
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Python inheritance

  • 1. Inheritance isthe capabilityof one classtoderive orinheritthe propertiesfromanotherclass.The benefitsof inheritance are: It representsreal-worldrelationshipswell. It providesreusabilityof acode.We don’thave to write the same code againand again.Also,itallowsusto add more featurestoa class withoutmodifyingit. It istransitive innature,whichmeansthatif classB inheritsfromanotherclassA,thenall the subclassesof B would automaticallyinheritfromclassA. # A Pythonprogram to demonstrate inheritance # Base or Superclass.Note objectinbracket. # (Generally,objectismade ancestorof all classes) # InPython3.x "classPerson"is # equivalentto"classPerson(object)" classPerson(object): # Constructor def __init__(self,name): self.name=name # To get name def getName(self): returnself.name # To checkif thispersonisan employee def isEmployee(self): returnFalse # InheritedorSubclass(Note Personinbracket) classEmployee(Person): # Here we returntrue def isEmployee(self): returnTrue # Drivercode emp= Person("Geek1") # AnObjectof Person print(emp.getName(),emp.isEmployee()) emp= Employee("Geek2") #An Objectof Employee print(emp.getName(),emp.isEmployee())
  • 2. ============== Subclassing(Callingconstructorof parentclass) A childclassneedstoidentifywhichclassisitsparentclass.Thiscan be done bymentioningthe parent classname in the definitionof the childclass. Eg: class subclass_name (superclass_name): _ _ _ _ _ _ # Pythoncode to demonstrate howparentconstructors # are called. # parentclass classPerson( object): # __init__ isknownas the constructor def __init__(self,name,idnumber): self.name =name self.idnumber=idnumber def display(self): print(self.name) print(self.idnumber) # childclass classEmployee( Person): def __init__(self,name,idnumber,salary,post): self.salary=salary self.post=post # invokingthe __init__of the parentclass Person.__init__(self,name,idnumber) # creationof an objectvariable oran instance a = Employee('Rahul',886012, 200000, "Intern") # callingafunctionof the class Personusingitsinstance a.display() ==== Differentformsof Inheritance: 1. Single inheritance:Whenachildclassinheritsfromonlyone parentclass,itiscalledsingle inheritance.We sawan example above.
  • 3. 2. Multiple inheritance:Whenachildclassinheritsfrommultipleparentclasses,itiscalledmultiple inheritance. Unlike Javaand like C++,Pythonsupportsmultipleinheritance.We specifyall parentclassesasacomma-separated listinthe bracket. # Pythonexampletoshowthe workingof multiple # inheritance classBase1(object): def __init__(self): self.str1="Geek1" print("Base1") classBase2(object): def __init__(self): self.str2="Geek2" print("Base2") classDerived(Base1,Base2): def __init__(self): # Callingconstructorsof Base1 # and Base2 classes Base1.__init__(self) Base2.__init__(self) print("Derived") def printStrs(self): print(self.str1,self.str2) ob = Derived() ob.printStrs() ======= 3. Multilevel inheritance:Whenwe have achildand grandchild relationship. # A Pythonprogramto demonstrate inheritance # Base or Superclass.Note objectinbracket. # (Generally,objectismade ancestorof all classes) # InPython3.x "classPerson"is # equivalentto"classPerson(object)" classBase(object): # Constructor
  • 4. def __init__(self,name): self.name=name # To get name def getName(self): returnself.name # InheritedorSubclass(Note Personinbracket) classChild(Base): # Constructor def __init__(self,name,age): Base.__init__(self,name) self.age =age # To get name def getAge(self): returnself.age # InheritedorSubclass(Note Personinbracket) classGrandChild(Child): # Constructor def __init__(self,name,age,address): Child.__init__(self,name,age) self.address=address # To get address def getAddress(self): returnself.address # Drivercode g = GrandChild("Geek1",23,"Noida") print(g.getName(), g.getAge(),g.getAddress())