class Myclass(object):

    def __init__(self):
        pass

    #必须实例化才能调用
    def sayhi(self):
        print 'hello' 

    #静态方法,跟类没什么关系,不需要实例化即可调用,类的工具包
    @staticmethod
    def sayhi2(self):
        print 'hello2'

    #不需要实例化即可调用,不能访问实例数据
    @classmethod  
    def sayhi3(self):
        print 'hello3'

    #将函数变成静态属性
    @property  
    def sayhi4(self):
        print 'hello3'

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-29
  • 2021-05-23
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案