Created
September 30, 2017 03:04
-
-
Save Per48edjes/dcecb5a540565588eb6f2dc4ca3ae631 to your computer and use it in GitHub Desktop.
Comparing in-memory locations of lists vs. slices of list vs. reassigning elements to list reference
This file contains hidden or 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 = [1,2,3] | |
def test(): | |
print("x-slice id before",id(x[:])) | |
print("x-slice before", x[:]) | |
x[:] += [4] | |
print("x-slice id after",id(x[:])) | |
print("x-slice after", x[:]) | |
print("x id", id(x)) | |
print("x", x) | |
test() | |
print("x id", id(x)) | |
print("x", x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment