URL:

https://www.the5fire.com/python-property-staticmethod-classmethod.html

#coding=utf-8

class MyClass(object):
    def __init__(self):
        print 'init'
        self._name = 'the5fire'


    @staticmethod
    def static_method():
        print 'this is a static method!'

    @classmethod
    def class_method(cls):
        print 'This is a class method', cls
        print 'visit the property of the class:', cls.name
        print 'visit the static method of the class: ', cls.static_method()
        instance = cls()
        print 'visit the normal method of the class: ', instance.test()

    def test(self):
        print 'call test'

    @property
    def name(self):
        return self._name

if __name__ == '__main__':
    print 'hahahah'
    MyClass.static_method()
    MyClass.class_method()
    mc = MyClass()
    mc.test()
    print mc.name
    # mc.name = 'huyang'
    # print mc.name

通过代码学习python之@property,@staticmethod,@classmethod

相关文章:

  • 2022-12-23
  • 2021-08-14
  • 2021-07-07
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
猜你喜欢
  • 2022-12-23
  • 2021-11-05
  • 2021-09-05
  • 2021-12-18
  • 2021-12-27
  • 2021-10-15
  • 2021-06-11
相关资源
相似解决方案