-
-
Save IndhumathyChelliah/ee2a5c4f3579bc0064c3082e139a5877 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x={'a':1,'b':2,'c':3} | |
y=x | |
print (x)#Output:{'a': 1, 'b': 2, 'c': 3} | |
print (y)#Output:{'a': 1, 'b': 2, 'c': 3} | |
#Both x and y will point to same object in memory. | |
print (id(x))#Output:19020728 | |
print (id(y))#Output:19020728 | |
# we are modifying only 'x' value.'y' value also modified. | |
x['d']=4 | |
print (x)#Output:{'a': 1, 'b': 2, 'c': 3, 'd': 4} | |
print(y)#Output:{'a': 1, 'b': 2, 'c': 3, 'd': 4} | |
#Both 'x' and 'y' now point to same dict object in memory. | |
print (id(x))#Output:19020728 | |
print (id(y))#Output:19020728 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment