Skip to content

Instantly share code, notes, and snippets.

@AdamGold
Created March 9, 2019 16:29
Show Gist options
  • Save AdamGold/4253cd76d166b1d87d7cf6aedff9f977 to your computer and use it in GitHub Desktop.
Save AdamGold/4253cd76d166b1d87d7cf6aedff9f977 to your computer and use it in GitHub Desktop.
In [25]: dis.dis("t[a] += b")
1 0 LOAD_NAME 0 (t)
2 LOAD_NAME 1 (a)
4 DUP_TOP_TWO
6 BINARY_SUBSCR
8 LOAD_NAME 2 (b)
10 INPLACE_ADD --> (value in t[a]) += b --> succeeds because list is mutable
12 ROT_THREE
14 STORE_SUBSCR --> Assign t[a] = our list --> Fails, t[a] is immutable.
16 LOAD_CONST 0 (None)
18 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment