类__init__ Processing.py中的可变变量

时间:2018-02-23 21:56:33

标签: python class

我有以下代码:

class fish:

    def __init__(self,foods):
        self.foods = foods

    def log(self):
        print self.foods

dog = [10,20,30] 

f = fish(dog)

dog = [1,5,5]

f.log()

当我运行而不是打印[1,5,5]时,它会打印[10,20,30]。有没有办法让我用变量狗更新f.foods而不必在类fish中编写一个新函数来更新self.foods?

0 个答案:

没有答案