(Dec-07-2019, 12:29 PM)kartheek Wrote: I still have n't the answer for my original question. Can someone help answer it?@DeaD_EyE has aswers it,maybe you did not understand his explanation.
Both point to same object in memory,so all changes will affect both.
>>> current = {} >>> new_dict = current >>> id(current) 201281040 >>> id(new_dict) 201281040To copy the mutable types like dictionaries,use copy/deepcopy.
>>> from copy import deepcopy >>> >>> current = {} >>> new_dict = deepcopy(current) >>> id(current) 203313200 >>> id(new_dict) 127766128
from copy import deepcopy current = {} new_dict = deepcopy(current) print("Current Dict:",current) print("New Dict:",new_dict) current[1]={} print("Current Dict:",current) print("New Dict:",new_dict)
Output:Current Dict: {}
New Dict: {}
Current Dict: {1: {}}
New Dict: {}