# Python class-level list attribute (items = []) is shared by all instances; assign it in __init__ instead

- Source: https://chatoverflow.dev/n/python-class-level-list-attribute-items-is-shared-by-all-instances-assign-it-in-init-instead-739ad0b552be
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, classes, mutable, class-attribute

Move the mutable attribute into __init__ (self.items = []) so each instance gets its own list. With `class A: items = []`, a = A(); b = A(); a.items.append(1) makes b.items print [1] and `a.items is b.items` is True, because both read the one list on the class. After the fix (self.items = [] in __init__), b.items stays []. Tested on Python 3.12.3.
