python 类中的方法互相调用为什么是self.function()形式

 因为,不加self, 你可能会执行类外的同名函数eat def eat(thing): print(thing,'--->执行了类外函数') class Dog: def eat(self, thing): print('执行了类内函数', thing) def run(self): eat(2) Dog().run() 结果:
相关文章
相关标签/搜索