Created
August 26, 2016 00:41
-
-
Save motivic/73a66f39f6ddc409b23cf7eb72f2059b to your computer and use it in GitHub Desktop.
Python lexical scoping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://google.github.io/styleguide/pyguide.html | |
| i = 4 | |
| def foo(x): | |
| def bar(): | |
| print i, | |
| # ... | |
| # A bunch of code here | |
| # ... | |
| for i in x: # Ah, i *is* local to Foo, so this is what Bar sees | |
| print i, | |
| bar() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So foo([1, 2, 3]) will print 1 2 3 3, not 1 2 3 4.