How to define the inheritance of python class
This article mainly introduces the relevant knowledge of "how to define the inheritance of python class". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to define the inheritance of python class" can help you solve the problem.
Description
1. Based on an existing class to obtain all its capabilities, and to extend a more powerful class, you can use the class to inherit it at this time.
The inherited class is called the parent class (or base class), and the heir is called the subclass (or derived class).
2. In the definition of class inheritance, add parentheses after the subclass name to write to the parent class.
Class parent class: implementation of the parent class class subclass (parent class): implementation of the subclass
Example
Class A: def _ init__ (self): self.apple = 'apple' def have (self): print (' I hava an', self.apple) class B (A): def who (self): print ('I am an object of B') this is the end of the introduction on "how to define inheritance of python classes". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.