#! /Usr/bin/Python #-*-coding: UTF-8-*-Class A: def f_method (self, X): Print "% s, % s" % (self, x) @ staticmethod def f_smethod (x): Print "% s" % (x) @ classmethod def f_cmethod (CLS, X): print '% s, % s' % (CLS, X) A = a (). f_smethod (1). f_smethod (1). f_cmethod (1). f_cmethod (1). f_method (1)
Returned results:
11 _ main _. A, 1 _ main _. A, 1 <__ main _. A instance at 0x7f05613b4c68>, 1
Member method: instance objects must be called. The self object is an instance object. During the call, A is implicitly passed to the self object.
Class Method: You can use not only instance objects, but also class objects. The CLs parameter is a class object.
Static Method: You can call not only instance objects, but also class objects. Different from member methods and class methods, it requires instance objects or
The class object is passed in as a hermit parameter. Static methods are similar to common non-class methods and can be used as some common methods encapsulated in the form of classes.