静态方法和类方法的定义

class DemoMthd: def __init__(self,x=0): self.x=x @staticmethod #静态方法装饰器 def static_mthd(): print('调用了静态方法!') #print(self.x) #在静态方法中不是使用实例属性 @classmethod #类方法装饰器 def class_mthd(cls):
相关文章
相关标签/搜索