实例方法,类方法,静态方法
class Foo():
h = "hello world"
def __init__(self, key, value):
self.key = key
self.value = value
def foo_test(self):
print("实例方法")
print(self.h)
print(self.key + self.value)
print("-------"*5)
@staticmethod
def foo_static():
print("静态方法")
print(Foo.h)
print("-------" * 5)
@classmethod
def foo_class(cls):
print("类方法")
key = 1
value = 2
dite = cls(key, value)
dite.foo_test()
if __name__ == '__main__':
f = Foo(5,6)
f.foo_test()
f.foo_static()
f.foo_class()
print("-----"*4)
Foo.foo_static()
Foo.foo_class()
窈窕包包,君子好逑