

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 does Python's super() work with multiple inheritance?
Before going to explain super() first we need to know about multiple inheritance concept.
Multiple inheritance : Means one child class can inherit multiple parent classes.
In the following example Child class inherited attributes methods from the Parent class.
Example
class Father: fathername = "" def father(self): print(self.fathername) class Mother: mothername = "" def mother(self): print(self.mothername) class Child(Father, Mother): def parent(self): print("Father :", self.fathername) print("Mother :", self.mothername) s1 = Child() s1.fathername = "Srinivas" s1.mothername = "Anjali" s1.parent()
Output
Father : Srinivas Mother : Anjali
In the following example shows ( i.e) super() works with multiple inheritances
super() : The super function can be used to replace the explicit call to
Example
class Father: fathername = "" def father(self): print(self.fathername) class Mother: mothername = "" def mother(self): print(self.mothername) class Child(Father, Mother): def parent(self): super().__init__() print("i am here") print("Father :", self.fathername) print("Mother :", self.mothername) s1 = Child() s1.fathername = "Srinivas" s1.mothername = "Anjali" s1.parent()
When you run the program, the output will be
Output
i am here Father : Srinivas Mother : Anjali
- Related Questions & Answers
- How does class inheritance work in Python?
- Does Python support multiple inheritance?
- How does Inheritance work in Ruby?
- How does Python's Matplotlib.pyplot.quiver exactly work?
- How does Das Keyboard’s Work?
- Does Java support multiple inheritance? Why? How can we resolve this?
- Role of super Keyword in Java Inheritance
- How does BackReference work with Python Regular Expression with Unicode?
- How does Xiaomi’s Foldable Electric Bicycle Work?
- How does Selenium WebDriver's isDisplayed() method work?
- How does modulus work with complex numbers in Python?
- How does linear regression work with Tensorflow in Python?
- How does Python while loop work?
- How we can extend multiple Python classes in inheritance?
- C# and Multiple Inheritance
Advertisements