静态方法:只是名义上归类管理,实际上在静态方法里不能访问类或实例中的任何属性
class Dog(object): def __init__(self,name): self.name=name @staticmethod def eat(self,food): print('%s is eating %s'%(self.name,food)) d=Dog('wangcai') d.eat(d,'骨头') >>>wangcai is eating 骨头
class Dog(object): def __init__(self,name): self.name=name @staticmethod def eat(name1,food): print('%s is eating %s'%(name1,food)) d=Dog('wangcai') d.eat('旺财','骨头') >>>旺财 is eating 骨头