class Person: def __init__(self, name, age): self.name = name self.age = age @property def play(self): print('---------') @classmethod def study(cls): print(cls) @staticmethod def statics(): print('++++++++') ax = Person("shuaige", 18) ax.play # 加了装饰器之后的调用,不加时调用:ax.play() ax.study() ax.statics()
@property # 可让实例对象用调用属性的形式调用方法
@classmethod # 可让实例对象获取类本身
@staticmethod # 传参时不需要传self