Reference post: http://pyzh.readthedocs.io/en/latest/python-magic-methods-guide.html
Reference Blog English Original: http://www.rafekettler.com/magicmethods.html
Construction Method:
1, __new__: The first call, remove the CLS parameter, and pass all other parameters to __init__, only applicable to the inheritance unchanged analogy such as int, tuple,string.
2. __init__: Initialization method
3. __DEL__: Destroy the object, for example, when the object is destroyed by closing the open file.
Comparison operators:
1, __cmp__: If all the comparison standards are unified, can be achieved through this implementation, otherwise you have to implement other comparison operators in turn. (Self>other returns 1)
2, __eq__, __ne__, __lt__, __gt__, __le__, __ge__: =,! =, <,;, <=, >=
3, Functools has a class decorator, as long as the definition of __eq__ and another operator, you can help to implement the comparison method, @total_ordering.
Numeric operator: unary
1, __pos__: Take positive
2, __neg__: Take negative
3. __abs__: Absolute Value
4, __invert__: Take the inverse operator ~
5, __round__: approximate number of digits
6. __floor__: Rounding Down
7, __ceil__: Rounding up
8, __trunc__: Take the distance 0 nearest integer
Number operator: two Yuan
1, __add__
2, __sub__
3, __mul__
4, __floordiv__://
5, __div__:/
6, __mod__
7, __divmod__
Python Python Magic Method (pending pits)