KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What I want is this behavior: class a: list = [] x = a() y = a() x.list.append(1) y.list.append(2) x.list.append(3) y.list.append(4) print(x.list) # prints [1, 3] print(y.list) # prints [2, 4] Of course, what really happens when I print is: print(x.list) # prints [1, 2, 3, 4] print(y.list) # prints [1, 2, 3, 4] Clearly they are sharing the data in class a . How do I get separate instances to achieve the behavior I desire?
Tags (comma-separated)
Save Edits
Cancel