-
-
Save IndhumathyChelliah/a5b5e5223924b4c2ecd102d712595b7c 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
from copy import deepcopy | |
x=[1,2,[3,4]] | |
#deepcopying x | |
y=deepcopy(x) | |
#Modifying elements in the outer list. | |
#It is not reflected in the deepcopied list. | |
x[0]=99 | |
print (x)#Output:[99, 2, [3, 4]] | |
print (y)#Output:[1, 2, [3, 4]] | |
#Modifying elements in the nested list. | |
#It is also not reflected in the deepcopied list. | |
x[2][0]=555 | |
print (x)#Output:[99, 2, [555, 4]] | |
print (y)#Output:[1, 2, [3, 4]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment