1. What is inheritance?
New classes don't have to be written from scratch
The new class inherits from the existing class and automatically has all the functionality of the existing class
New classes only need to write new features that are missing from existing classes
2. Benefits of Inheritance
Reusing existing code
Automatically has all the features of an existing class
You just need to write the missing new features
3. Parent and Child classes
1 #defines a parent class, also known as a base class, a superclass2 classfather (object):3 def __init__(self,name,gender):4Self.name =name5Self.gender =Gender6 7 #defines a subclass, also known as a derived class, that inherits a class8 classChild (father):9 def __init__(self,name,gender,score):Ten #initializes the parent class, otherwise the child inheriting from father will have no name and gender OneSuper (Child,self).__init__(Name,gender) ASelf.score =score - -t = Child ('Tom','Six','98') the PrintT.name
4. Characteristics of inheritance
Subclasses and parent classes are the IS relationships
class Child (father): Pass == Child ()
P is a father but not a child
S is a father and also a person
First-entry Python inheritance