Created
October 9, 2011 15:58
-
-
Save pikeas/1273832 to your computer and use it in GitHub Desktop.
Unbound variable?
This file contains 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
def foo(): | |
a = 10 | |
def _foo(): | |
print a | |
_foo() | |
#Outputs 10 | |
def foo(): | |
a = 10 | |
def _foo(): | |
a += 10 | |
print a | |
_foo() | |
#Fails with UnboundLocalError: local variable 'a' referenced before assignment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment