The binding methods in the class are divided into two types: 1. Binding Methods
Special: the user who binds the API will call the API and the user who calls the API will automatically pass in the API as the first parameter.
Object binding method: If the function defined in the class does not have any modifier, it is bound to the object by default.
Method of binding to a class: Add a modifier classmethod to the class definition function and bind it to the class.
2. Non-binding method
Special: a non-binding method is a common function, that is, it is not bound to a class or an object, so that the class and object can be called, But no matter who calls it, it is a common function, no automatic Value Transfer Function
Three methods
Class FOO: # method of binding objects def func1 (Self): Print ("func1") # method of binding to classes @ classmethod def func2 (CLS): Print ("func ", CLs) # non-binding method @ staticmethod def func3 (x, y): Print (x + y)
Call Method
Method of binding an object. You can call an object or call a class, but you need to pass in the object.
F1 = Foo () # format of the bound object f1.func1 () Foo. func1 (F1)
Binding class
# Bind the class method Foo. func2 () f1.func2 ()
Non-binding method
# Non-binding method f1.func3 (1, 2) Foo. func3 (1, 2)
Object-oriented -- binding and non-binding methods