This article mainly introduces detailed information about the inheritance instances of the Python class. For more information about the inheritance instances of the Python class, see the following article, for more information, see
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!
The above is a detailed description of the Python class inherited instance code. For more information, see other related articles in the first PHP community!