Skip to content

Instantly share code, notes, and snippets.

@nedbat
Created November 17, 2016 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nedbat/e89fa710db0edfb9057dc8d18d979f9c to your computer and use it in GitHub Desktop.
Save nedbat/e89fa710db0edfb9057dc8d18d979f9c to your computer and use it in GitHub Desktop.
>>> def f(x, y):
... print("Hello")
... if x:
... y += x
... print(x, y)
... return x+y
...
>>> import dis
>>> dis.dis(f)
2 0 LOAD_GLOBAL 0 (print)
2 LOAD_CONST 1 ('Hello')
4 CALL_FUNCTION 1
6 POP_TOP
3 8 LOAD_FAST 0 (x)
10 POP_JUMP_IF_FALSE 20
4 12 LOAD_FAST 1 (y)
14 LOAD_FAST 0 (x)
16 INPLACE_ADD
18 STORE_FAST 1 (y)
5 >> 20 LOAD_GLOBAL 0 (print)
22 LOAD_FAST 0 (x)
24 LOAD_FAST 1 (y)
26 CALL_FUNCTION 2
28 POP_TOP
6 30 LOAD_FAST 0 (x)
32 LOAD_FAST 1 (y)
34 BINARY_ADD
36 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment