I am running into some odd behavior with a python class, and I was hoping someone might be able to explain the cause and fix. I am using python 3.8.5. The problem is that when I have a list of class attributes and I try and update them, that they don't seem to get updated. Here is a simple example.
class testclass:
def __init__(self) -> None:
self.a = 2
self.b = 3
self.c = 4
def update(self):
for s in [self.a, self.b, self.c]:
s = 10
def response(self):
self.update()
print([self.a, self.b, self.c])
if __name__ == '__main__':
myclass = testclass()
myclass.response()
The output that I get is [2, 3, 4], when it should be [10,10,10] after the update()
method is applied, right? Is there a better way to do something like this?