不同的方法可以通过类变量进行通信:
#!/usr/bin/env python
class dog:
def sayHi(self):
print 'Himaster,I am your little dog,who do you want me to bite...'
favorate_food = 'bone' #函数内部变量,其它方法无法引用
self.FavorFood = favorate_food #类变量,变成类变量后,函数间可以通过类变量通信
defeat(self,food_type):
if food_type == self.FavorFood :
print 'I likeit very much..thanks'
else:
print 'Do notgive me this bull shit...'
d=dog()
d.sayHi()
d.eat('bone')