With a optional argument in a function it is possible to access quantities of a different instance of a class. (see code below). Am I doing something wrong, or this this expected behavior?
Linux, Python 3.7.3 [GCC 7.3.0]
class Cat:
def __init__(self, name):
self.name = name
print(name)
def my(self, d = {}):
print('Before: ',d)
d[self.name] = str(self.name)
print('After: ',d)
tiger = Cat('Tiger')
tiger.my()
lion = Cat('Lion')
lion.my()
The code output is:
Tiger
Before: {}
After: {'Tiger': 'Tiger'}
Lion
Before: {'Tiger': 'Tiger'}
After: {'Tiger': 'Tiger', 'Lion': 'Lion'}