1. An empty class
1 # Filename:emptyclass.py 2 3 class Empty: 4 Pass 5 6 e = Empty ()7print#<__main__. Empty object at 0x022f6df0>
2. Methods of the class
The method of the class must have an extra first parameter, self, which points to the object itself. The call does not need to be assigned, and Python provides this value.
__init__ (self [, param1,param2 ...])
Run immediately when an object of the class is established.
__del__ (self)
It is called when the object dies, but it is difficult to guarantee when the method will run.
3. Inheritance
1 #Filename:inherit.py2 classFather:3 def __init__(self,name):4Self.name =name5 6 classChild (Father):7 def __init__(self,name,age):8Father.__init__(Self,name)9Self.age = Age
Python does not automatically call the constructor of the base class.
Python supports multiple inheritance . When it cannot find the method called in the current class, it is looked up in the parent class, in the order of inheritance .
4. Simulating abstract classes
Notimplementederror class
Python language and the like