@staticmethod
不需要实例化一个对象再调用,直接类名.方法名()便可调用。
class A(object):
bar = 1
def foo(self):
print("foo call")
@staticmethod
def static_foo():
print("static foo:")
print(A.bar)
@classmethod
def class_foo(cls):
print("class foo:")
print(cls.bar)
cls().foo()
A.static_foo()
A.class_foo()