错误如下:
>>> class A: def a(self): print("I'm a") >>> A.a() Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> A.a() TypeError: unbound method a() must be called with A instance as first argument (got nothing instead) 错误原因:函数a()非静态方法,故需实例化然后才能使用,改正如下:class A: def a(self): print("I'm a") obj = A() obj.a() 或者将a()改为静态方法即可,如下:class A: @staticmethod def a(): print ("I'm a") A.a()