A class keeps its items in a list written in the class body. class Bag: items = [] def add(self, x): self.items.append(x) return self p = Bag().add(1) q = Bag().add(2) q.items = [9] q.add(3) print(p.items, q.items, Bag.items) What does the program print?
Log in to join the discussion.
Loading…