In Python 3.8.3, I created a simple class that contains a dictionary as follows:
class trees:
fruits = {}
def __init__(self, initFruits = {}):
self.fruits = initFruits
def printFruits(self):
for f in self.fruits:
print(f, self.fruits[f])
Next, I call the class to create an empty object, and populate it
marigold = trees()
marigold.fruits["apple"] = 3
marigold.printFruits()
Printing the contents gives the expected: apple 3
However, I then want to create another empty object
riverdale = trees()
riverdate.printFruits()
Printing the contents gives me the same out as the Marigold object: apple 3
Furthermore, when I add more items into the Riverdale object, the Marigold object gets altered as well
riverdale.Fruits["orange"] = 5
marigold.printFruits()
Its contents become:
apple 3
orange 5
I wanted to create a separate object, why are they somehow linked?