The Python class resembles a container and is a dynamic container that can add content to it at any time: its functions, its members.
For example, the default is to create an empty Python class, and if you forget to add a member function to it, you can do so.
Class Empty:
Pass
1. Add constructors
#这里必须要传入一个参数
#该参数也就是调用方的输入数据
#这里就是Empty的一个实例对象
def Empty_con (E):
The print ' empty object starts to construct '
Print (Type (e))
empty.__init__ = Empty_con
Here we test:
e1 = Empty ()
The results of the discovery are as follows:
The empty object starts to construct the
<type ' instance ' >
2. For the same reason, we can add (or replace) his destructor
def empty_des (E):
The print ' object starts to deconstruct '
Print (Type (e))
empty.__del__ = Empty_des
Here we also test the destructor:
E2 = Empty ()
del E2
The output is as follows:
' The object begins to deconstruct
<type ' instance ' >
3. We can also add a member variable to a class (type) by analogy.
When you can also add members to objects only
empty.x = 100
EMPTY.Y = 200
by calling dir (empty) you can clearly see the member structure below empty.
Class characteristics of Pyton