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()

相关文章:

  • 2021-09-17
  • 2021-11-01
  • 2021-11-08
  • 2021-10-23
  • 2021-07-01
  • 2021-08-26
  • 2021-09-28
猜你喜欢
  • 2021-12-01
  • 2021-09-17
  • 2021-10-03
  • 2021-07-15
  • 2021-08-23
  • 2021-10-26
  • 2021-08-29
相关资源
相似解决方案