我有以下代码:
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?