a = A()
a.foo1("world")# 输出hello world
A.foo1("world")# 输出hello world
2)对于类方法foo2,它是正常的函数,是类的实例的函数,只能通过a调用:
a.foo2('world')# 输出: hello world
A.foo2('world')# 报错: unbound method foo2() must be called with A instance as first argument (got str instance instead)
classA:
a ='a'@staticmethoddeffoo1(name):print("hello ", name)deffoo2(self, name):print("hello ", name)print(A.a)print(A.foo2("xx"))#报错:unbound method foo2() must be called with A instance as first argument (got str instance instead)@classmethoddeffoo3(cls, name):print("hello ", name)print(A.a)print(cls.foo2("xx"))