I have a small piece of code where I am trying to change the member values of an array of class objects.
class Test(object):
def __init__(self):
self.id = 0
test = []
temp = Test()
for i in range(5):
temp.id = i
test.append(temp)
print(test[len(test)-1].id)
print()
for i in range(5):
print(test[i].id)
However, I am getting the following result and I'm unable to figure out why? Any help is appreciated.
0
1
2
3
4
4
4
4
4
4

Testobject. You'll have to create more of them.