Skip to content

Instantly share code, notes, and snippets.

@Per48edjes
Created September 30, 2017 03:04
Show Gist options
  • Save Per48edjes/dcecb5a540565588eb6f2dc4ca3ae631 to your computer and use it in GitHub Desktop.
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
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