How to Do Hybrid Inheritance in Python

In this article, you will learn how to do hybrid inheritance in Python. Hybrid inheritance is a combination of multilevel inheritance and multiple inheritance. #…

The post How to Do Hybrid Inheritance in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to do hybrid inheritance in Python.

Hybrid inheritance is a combination of multilevel inheritance and multiple inheritance.

# This class is the base class
class Father:
def func1(self):
print("This function is in Father")

# This class inherits from Father
class FirstChild(Father):
def func2(self):
print("This function is in FirstChild")

# This class inherits from Father
class SecondChild(Father):
def func3(self):
print("This function is in SecondChild")

# This class inherits from both FirstChild and Father
class GrandChild(FirstChild, Father):
def func4(self):
print("This function is in GrandChild")

object = GrandChild()
object.func1()
# This function is in Father

object.func2()
# This function is in FirstChild

Note: The class GrandChild is an example of hybrid inheritance.

The post How to Do Hybrid Inheritance in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-02-28T17:28:23+00:00) How to Do Hybrid Inheritance in Python. Retrieved from https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/

MLA
" » How to Do Hybrid Inheritance in Python." Ariessa Norramli | Sciencx - Sunday February 28, 2021, https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/
HARVARD
Ariessa Norramli | Sciencx Sunday February 28, 2021 » How to Do Hybrid Inheritance in Python., viewed ,<https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Do Hybrid Inheritance in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/
CHICAGO
" » How to Do Hybrid Inheritance in Python." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/
IEEE
" » How to Do Hybrid Inheritance in Python." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/. [Accessed: ]
rf:citation
» How to Do Hybrid Inheritance in Python | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/02/28/how-to-do-hybrid-inheritance-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.