- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Does Python support multiple inheritance?
Yes, Python supports multiple inheritance. Like C++, a class can be derived from more than one base classes in Python. This is called Multiple Inheritance.
In multiple inheritance, the features of all the base classes are inherited into the derived class. Let us see the syntax −
Syntax
Class Base1: Body of the class Class Base2: Body of the class Class Base3: Body of the class . . . Class BaseN: Body of the class Class Derived(Base1, Base2, Base3, … , BaseN): Body of the class
The Derived class inherits from both Base1, Base2 and Base3classes.
Example
In the below example, Bird class inherits the Animal class.
Animal is the parent class also known as super class or base class.
Bird is the child class also known as sub class or derived class.
The issubclass method ensures that Bird is a subclass of Animal class.
class Animal: def eat(self): print("It eats insects.") def sleep(self): print("It sleeps in the night.") class Bird(Animal): def fly(self): print("It flies in the sky.") def sing(self): print("It sings a song.") print(issubclass(Bird, Animal)) Koyal= Bird() print(isinstance(Koyal, Bird)) Koyal.eat() Koyal.sleep() Koyal.fly() Koyal.sing()
Output
True It eats insects. It sleeps in the night. It flies in the sky. It sings a song. True
- Related Articles
- Does Java support multiple inheritance? Why? How can we resolve this?
- Does MySQL support table inheritance?
- Does java support hybrid inheritance?
- How does Python's super() work with multiple inheritance?
- Does Python support polymorphism?
- How does class inheritance work in Python?
- Multiple Inheritance in C++
- Multiple inheritance in JavaScript
- Java and multiple inheritance
- C# and Multiple Inheritance
- How we can extend multiple Python classes in inheritance?
- Multiple inheritance by Interface in Java
- Java Program to Implement Multiple Inheritance
- Haskell Program to Implement multiple inheritance
- How does class variables function in multi-inheritance Python classes?

Advertisements