Detailed description of Python class inheritance instances and python inheritance instances
Python class inheritance
Since Python is object-oriented, it certainly supports class inheritance. the inheritance of Python implementation classes is simpler than that of Javascript.
Parent class:
class Parent: parentAttr = 100 def __init__(self): print("parent Init") def parentMethod(self): print("parentMethod") def setAttr(self,attr): self.parentAttr = attr def getAttr(self): print("ParentAttr:",Parent.parentAttr)
Child class
class Child(Parent): def __init__(self): print("child init") def childMethod(self): print("childMethod")
Call
p1 = Parent(); p1.parentMethod(); c1 = Child(); c1.childMethod();
Output:
parent Init parentMethod child init childMethod Press any key to continue . . .
Python supports multi-Inheritance
Class A: # define class ..... class B: # define class B ..... class C (A, B): # inherit classes A and B .....
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!