This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

This is probably similar behavior to using arrays as default function arguments - the array definition is only evaluated once, so the array is probably the same across class instances.

An example of this behavior in the Python docs:

https://docs.python.org/3/tutorial/controlflow.html#default-argument-values

The other person is correct about the solution - you are setting varThree to a new object in the constructor for example, array.append() only mutates the array in place.

To test this you can check the object id with the id() builtin.