Why is this not working as expected (at least for me)? I can't figure why.
class Fred:
def __init__(self):
self.a=0
fred=Fred()
lista=[]
for i in range(5):
fred.a=i
lista.append(fred)
for i in lista:
print(str(i.a))
All I get is 5 times the number 4 and not from 0 to 4. Any comments? Thanks
listaare referencing to the same element,, and the you see the number 4 since its the latest updated value of the objectfred