Skip to content

Instantly share code, notes, and snippets.

@disconnect3d
Last active October 19, 2019 10:48
Show Gist options
  • Save disconnect3d/48075bcb3e5595cc2525c8ac6829cf20 to your computer and use it in GitHub Desktop.
Save disconnect3d/48075bcb3e5595cc2525c8ac6829cf20 to your computer and use it in GitHub Desktop.
In [9]: def foo():
...: return x
...: def foofoo(x):
...: return x
...: def bar():
...: x += 1
...: def foobar():
...: global x
...: x += 1
...:
...:
In [10]: dis.dis(foo)
2 0 LOAD_GLOBAL 0 (x)
2 RETURN_VALUE
In [11]: dis.dis(foofoo)
4 0 LOAD_FAST 0 (x)
2 RETURN_VALUE
In [12]: dis.dis(bar)
6 0 LOAD_FAST 0 (x)
2 LOAD_CONST 1 (1)
4 INPLACE_ADD
6 STORE_FAST 0 (x)
8 LOAD_CONST 0 (None)
10 RETURN_VALUE
In [13]: dis.dis(foobar)
9 0 LOAD_GLOBAL 0 (x)
2 LOAD_CONST 1 (1)
4 INPLACE_ADD
6 STORE_GLOBAL 0 (x)
8 LOAD_CONST 0 (None)
10 RETURN_VALUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment