Skip to content

Instantly share code, notes, and snippets.

@dcrosta
Created May 8, 2015 11:23
Show Gist options
  • Save dcrosta/1118f562b42a4bd47528 to your computer and use it in GitHub Desktop.
Save dcrosta/1118f562b42a4bd47528 to your computer and use it in GitHub Desktop.
>>> def foo(a, b, c):
... if a:
... return b
... return c
...
>>> dis.dis(foo)
2 0 LOAD_FAST 0 (a)
3 POP_JUMP_IF_FALSE 10
3 6 LOAD_FAST 1 (b)
9 RETURN_VALUE
4 >> 10 LOAD_FAST 2 (c)
13 RETURN_VALUE
>>> def foo(a, b, c):
... if a:
... return b
... else:
... return c
...
>>> dis.dis(foo)
2 0 LOAD_FAST 0 (a)
3 POP_JUMP_IF_FALSE 10
3 6 LOAD_FAST 1 (b)
9 RETURN_VALUE
5 >> 10 LOAD_FAST 2 (c)
13 RETURN_VALUE
14 LOAD_CONST 0 (None) # Note that control will never reach here
17 RETURN_VALUE # so even though there's more bytecode, it
# won't impact run-time performance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment