Python class and Object Features, python Object Features
I will share some basic knowledge about the python class. I believe that you have a certain understanding of python. The python class mentioned today is suitable for those who are engaged in long-term product development.
Compared with other languages such as C ++ and JAVA, python oop is easier to understand and use. It removes some complex syntax features.
When you get started with the python class, you can think of it as a tree, trunk = parent class, and root = subclass.
The roots absorb the nutrition of the trunk, and can absorb the nutrition of several trunk at the same time. Therefore, python can carry out multi-inheritance and rewrite the attributes and methods of the parent class.
Class Person ():
Def _ init _ (self, name ):
Self. name = name
Def say (self): # object Method
Print self. name
Def _ notsay (self): # private Method
Print self. name
User = Person ('xiaoming ')
User. say ()
User. _ say ()
The above is a simple class definition, __init _ (). This is a class constructor. It is called when an object is generated. Other languages also have similar constructor methods.
Python has a garbage collection mechanism, so you do not need to define the destructor.