class T(object):
def func(self):
pass
@staticmethod
def sfunc(self):
pass
@classmethod
def cfunc(cls):
pass
一、python2
实例方法 T.func <unbound method T.func> T.func.__class__ <type 'instancemethod'> T.__dict__["func"] <function func at 0x0000000002DB8D68> T.__dict__["func"].__class__ <type 'function'> 静态方法 T.sfunc <function sfunc at 0x0000000002DB8EB8> T.sfunc.__class__ <type 'function'> T.__dict__["sfunc"] <staticmethod object at 0x0000000002E1CF48> T.__dict__["sfunc"].__class__ <type 'staticmethod'> 类方法 T.cfunc <bound method type.cfunc of <class '__main__.T'>> T.cfunc.__class__ <type 'instancemethod'> T.__dict__["cfunc"] <classmethod object at 0x0000000002DE3B58> T.__dict__["cfunc"].__class__ <type 'classmethod'> t=T() 实例方法 t.func <bound method T.func of <__main__.T object at 0x0000000002E32DD8>> t.func.__class__ <type 'instancemethod'> 静态方法 t.sfunc <function sfunc at 0x0000000002DB8EB8> t.sfunc.__class__ <type 'function'> 类方法 t.cfunc <bound method type.cfunc of <class '__main__.T'>> t.cfunc.__class__ <type 'instancemethod'>
二、python3
实例方法 T.func和T.__dict__["func"]均返回function T.func <function T.func at 0x00000000055B28C8> T.func.__class__ <class 'function'> T.__dict__["func"] <function T.func at 0x00000000055B28C8> T.__dict__["func"].__class__ <class 'function'> 静态方法 T.sfunc <function T.sfunc at 0x00000000055B2950> T.sfunc.__class__ <class 'function'> T.__dict__["sfunc"] <staticmethod object at 0x000000000557B198> T.__dict__["sfunc"].__class__ <class 'staticmethod'> 类方法 T.cfunc <bound method T.cfunc of <class '__main__.T'>> T.cfunc.__class__ <class 'method'> T.__dict__["cfunc"] <classmethod object at 0x00000000055B9BE0> T.__dict__["cfunc"].__class__ <class 'classmethod'> t=T() 实例方法 t.func <bound method T.func of <__main__.T object at 0x00000000055B9EB8>> t.func.__class__ <class 'method'> 静态方法 t.sfunc <function T.sfunc at 0x00000000055B2950> t.sfunc.__class__ <class 'function'> 类方法 t.cfunc <bound method T.cfunc of <class '__main__.T'>> t.cfunc.__class__ <class 'method'>