I tried to create two objects that both have their own inventories. As far as I'm concerned I successfully managed to create two different objects called my_bag and toms_bag This is the code I used
class bag(object):
def inventory_add(self, item):
self.inventory.append(item)
inventory = []
bags = [] #List of all bags
#Create bags
my_bag = bag()
my_bag.inventory_add("pencil")
bags.append(my_bag)
toms_bag = bag()
toms_bag.inventory_add("book")
bags.append(toms_bag)
for bag in bags: #Print inventories
print(bag, bag.inventory)
This is the result I get.
<__main__.bag object at 0x004D0830> ['pencil', 'book']
<__main__.bag object at 0x004D0790> ['pencil', 'book']
So why are the items added to both of their inventories? Are they even different objects now?