I want to create two instance of class , and send dict to init , but why the first class instance reference second class dict ?
class Test:
def __init__(self, *args, **kwargs):
print(kwargs)
self.k = kwargs
initDict = {'PP':{'a':1}}
newC1 = initDict.copy()
newC1['PP']['b'] = 2
qq1 = Test(**newC1)
newC2 = initDict.copy()
newC2['PP']['b'] = 999
qq2 = Test(**newC2)
print('---------------')
print(qq1.k)
print(qq2.k)
there is the result
{'PP': {'a': 1, 'b': 2}}
{'PP': {'a': 1, 'b': 999}}
---------------
{'PP': {'a': 1, 'b': 999}}
{'PP': {'a': 1, 'b': 999}}