encapsulation : Improve the security of the program , Put the data ( attribute ) And behavior ( Method ) Wrapping in class objects . Operate on attributes inside methods , stay
Class object . such , There is no need to care about the specific implementation details inside the method , This isolates the complexity .
stay Pvthon There is no special modifier for private properties in , If the property does not want to be accessed outside the class object , Use two... At the front ”_”.
Inherit : Improve code reusability
polymorphic : Improve the scalability and maintainability of the program
Grammar format
class Subclass class name ( Parent class 1, Parent class 2...) :
pass
If a class does not inherit any classes , Default inheritance object
Python Support for multiple inheritance
When you define subclasses , The constructor of the parent class must be called in its constructor
class Person(object): #Person Inherit object class
def __init__(self,name,age):