Python can inherit multiple parent classes, multiple inheritance.
Class supports the generation of multiple objects, inheritance of namespaces, operator overloading
1), class produces multiple instance objects
Two types of objects in the Python OOP model: Class objects and instance objects.
The class object provides the default behavior, which is the factory of the instance object. Instance objects are the actual objects that the program handles: each has a separate namespace. The class object comes as far as the statement, while the instance comes to the call. Each time a class is called, a new instance of the class is obtained.
A, class object provides default behavior
b, the instance object is the concrete element
2), class through inheritance to customize
A, class through inheritance to customize
B, class is a property inside a module
3), class can intercept Python operators
Common operator overloading methods
Method overload Call
__init__ constructor Method Object establishment: X=class ()
__del__ destructor Method Object retraction
__add__ operator + x+y,x+=y
__sub__ operator-X-y,x-=y
__OR__ operator | (bit or) X| Y x|=y
__repr__,__str__ printing, converting print X "__str__", repr (x), str (x)
__call__ function call X ()
__getattr__ Point number Operation x.undefined
__setattr__ Property Assignment Statement X.any=value
__GETITEM__ index Operation X[key], for loops and other iterators without __iter__
__SETITEM__ Index Assignment Statement X[key]=value
__len__ length Len (X), Truth test
__cmp__ comparison X==y,x
__lt__ Specific comparison x<y (or else __cmp__)
__eq__ Specific comparison x==y (or else __cmp__)
__radd__ Left add + noninstance + X
__iadd__ field (Enhanced) addition x+=y (or else __add__)
__ITER__ iterative environment for loops, tests, lists, mappings, and more
The names of all overloaded methods have two underscore characters before and after them, so that the variable names defined in the same class are distinguished from each other. The mapping of a particular method name to an expression or an operation is predefined by the Python language.
Python Class Summary