实例方法,类方法,静态方法

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()
posted @ 2019-06-05 11:47  菜菜_包包  阅读(261)  评论(0编辑  收藏  举报