Created
April 26, 2019 05:18
-
-
Save oakbani/c93d6b53d8b5fe9e833317e106588c5b 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
# Python List makes a shallow copy by default and doesn't copy-on-write. | |
list_a = [1,2,3] | |
list_shallow = list_a | |
list_shallow.append(4) | |
print(list_a) # [1, 2, 3, 4] | |
list_a.append(5) | |
print(list_shallow) # [1, 2, 3, 4, 5] | |
list_a = [1,2,3] | |
list_deep = list_a[:] | |
list_deep.append(4) | |
print(list_a) # [1, 2, 3] | |
list_a.append(5) | |
print(list_deep) # [1, 2, 3, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment