Skip to content

Instantly share code, notes, and snippets.

@jsocol
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save jsocol/1c1912c755512c41fc61 to your computer and use it in GitHub Desktop.

Select an option

Save jsocol/1c1912c755512c41fc61 to your computer and use it in GitHub Desktop.
def f1():
a = 0
a += 1
dis.dis(f1)
2 0 LOAD_CONST 1 (0)
3 STORE_FAST 0 (a)
3 6 LOAD_FAST 0 (a)
9 LOAD_CONST 1 (1)
12 INPLACE_ADD
13 STORE_FAST 0 (a)
16 LOAD_CONST 0 (None)
19 RETURN_VALUE
def f2():
a = 0
a = a + 1
2 0 LOAD_CONST 1 (0)
3 STORE_FAST 0 (a)
3 6 LOAD_FAST 0 (a)
9 LOAD_CONST 1 (1)
12 BINARY_ADD
13 STORE_FAST 0 (a)
16 LOAD_CONST 0 (None)
19 RETURN_VALUE
def f3():
a = []
a += [1]
2 0 BUILD_LIST 0
3 STORE_FAST 0 (a)
3 6 LOAD_FAST 0 (a)
9 LOAD_CONST 1 (1)
12 BUILD_LIST 1
15 INPLACE_ADD
16 STORE_FAST 0 (a)
19 LOAD_CONST 0 (None)
22 RETURN_VALUE
def f4():
a = []
a.extend([1])
2 0 BUILD_LIST 0
3 STORE_FAST 0 (a)
3 6 LOAD_FAST 0 (a)
9 LOAD_ATTR 0 (extend)
12 LOAD_CONST 1 (1)
15 BUILD_LIST 1
18 CALL_FUNCTION 1
21 POP_TOP
22 LOAD_CONST 0 (None)
25 RETURN_VALUE
def f5():
a = [5]
a[0] += 1
2 0 LOAD_CONST 1 (5)
3 BUILD_LIST 1
6 STORE_FAST 0 (a)
3 9 LOAD_FAST 0 (a)
12 LOAD_CONST 1 (0)
15 DUP_TOPX 2
18 BINARY_SUBSCR
19 LOAD_CONST 2 (1)
22 INPLACE_ADD
23 ROT_THREE
24 STORE_SUBSCR
25 LOAD_CONST 0 (None)
28 RETURN_VALUE
def f6():
a = ([],)
a[0] += [1]
2 0 BUILD_LIST 0
3 BUILD_TUPLE 1
6 STORE_FAST 0 (a)
3 9 LOAD_FAST 0 (a)
12 LOAD_CONST 1 (0)
15 DUP_TOPX 2
18 BINARY_SUBSCR
19 LOAD_CONST 2 (1)
22 BUILD_LIST 1
25 INPLACE_ADD
26 ROT_THREE
27 STORE_SUBSCR
28 LOAD_CONST 0 (None)
31 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment