代码1:
def test(): pass print(test)
输出:
<function fun at 0x000000000248A820B380>
代码2:
class Demo(): def fun1(self): pass @classmethod def fun2(cls): pass @staticmethod def fun3(self): pass demo = Demo() print(demo) print(demo.fun1) print(demo.fun2) print(demo.fun3)
输出:
<__main__.Demo object at 0x0000029CD0BB7C40> <bound method Demo.fun1 of <__main__.Demo object at 0x0000029CD0BB7C40>> <bound method Demo.fun2 of <class '__main__.Demo'>> <function Demo.fun3 at 0x0000029CD1005F30>
由此得出:
此外:
静态方法为什么是函数但是在类里 : 我觉得是语法糖。静态函数虽然并不真的跟着类在内存里,但是程序员写程序必须跟着类写,起到了规范整理的作用。