class Number():
list = []
number = Number()
number.list.append(0)
print number.list # [0]
newNumber = Number()
newNumber.list.append(1)
print newNumber.list # [0,1]
I have created two instance, why the newNumber.list object has the 0? Why the number and the newNumber use the same list? Anybody can help me? and Why the 'i' is not change in the follow?
class Number:
i = 0
number = Number()
number.i = 1
print number.i # 1
newNumber = Number()
print newNumber.i # 0
listas defined in your code belongs to theclassnot the instances. you need to writeself.list = []to have onelistper instance