- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How many types of inheritance are there in Python?
Inheritance is concept where one class accesses the methods and properties of another class.
- Parent class is the class being inherited from, also called base class.
- Child class is the class that inherits from another class, also called derived class.
There are two types of inheritance in python −
- Multiple Inheritance
- Multilevel Inheritance
Multiple Inheritance −
In multiple inheritance one child class can inherit multiple parent classes.
Example
class Father: fathername = "" def father(self): print(self.fathername) class Mother: mothername = "" def mother(self): print(self.mothername) class Daughter(Father, Mother): def parent(self): print("Father :", self.fathername) print("Mother :", self.mothername) s1 = Daughter() s1.fathername = "Srinivas" s1.mothername = "Anjali" s1.parent()
Output
Father : Srinivas Mother : Anjali
Multilevel Inheritance
In this type of inheritance, a class can inherit from a child class/derived class.
Example
#Daughter class inherited from Father and Mother classes which derived from Family class. class Family: def family(self): print("This is My family:") class Father(Family): fathername = "" def father(self): print(self.fathername) class Mother(Family): mothername = "" def mother(self): print(self.mothername) class Daughter(Father, Mother): def parent(self): print("Father :", self.fathername) print("Mother :", self.mothername) s1 = Daughter() s1.fathername = "Srinivas" s1.mothername = "Anjali" s1.family() s1.parent()
Output
This is My family: Father : Srinivas Mother : Anjali
- Related Articles
- How many types of wool are there?
- How many types of motion are there ?
- How many types of forces are there ?
- How many types of fibres are there?
- How many types of constructors are there in Java?
- How many different types of eclipses are there?
- How many types of JDBC Drivers are there?
- How many types of Third-Party Risks are there?
- How many types of Result Sets are there in JDBC What are they?
- How many Vitamins are there?
- How many joints are there?
- How many integers are there?
- How many Blockchains are there?
- How many methods of separation are there?
- a) How many milliamperes are there in 1 ampere?b) How many microamperes are there in 1 ampere?

Advertisements