python学习笔记——装饰器、类方法、实例方法

@staticmethod、@classmethod、@property
@classmethod

class People():
    def run(self):
        print('this is run')
    @classmethod
    def relax(cls):
        print('this is relax')
xiaoming = People()
xiaoming.run()#this is run
People.relax()#this is relax
People.run()#TypeError: run() missing 1 required positional argument: 'self'

你可能感兴趣的:(python学习笔记,python)