类的另外的特性,装饰器方法:静态方法(staticmethod)、类方法(classmethod)、属性方法(property)
一、静态方法
在方法名前加上@staticmethod装饰器,表示此方法为静态方法
class Dog(object): def __init__(self,name): self.name = name @staticmethod #在方法前加上staticmethod 装饰器定义静态方法 def eat(): print("dog is eating"
类的另外的特性,装饰器方法:静态方法(staticmethod)、类方法(classmethod)、属性方法(property)
在方法名前加上@staticmethod装饰器,表示此方法为静态方法
class Dog(object): def __init__(self,name): self.name = name @staticmethod #在方法前加上staticmethod 装饰器定义静态方法 def eat(): print("dog is eating"
相关文章: