Skip to content

Instantly share code, notes, and snippets.

@kojiromike
Last active December 23, 2015 15:29
Show Gist options
  • Save kojiromike/6655738 to your computer and use it in GitHub Desktop.
Save kojiromike/6655738 to your computer and use it in GitHub Desktop.
Example of differences between slice copy and slice mutation of a list
>>> a = b = c = list(range(12))
>>> a is b and a is c
True
>>> a = a[2:]
>>> a
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
>>> a is b and a is c
False
>>> b is c
True
>>> b[:2] = []
>>> b is c
True
>>> b
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
>>> b is a
False
>>> b == a
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment