Skip to content

Instantly share code, notes, and snippets.

@non-static
Created December 1, 2013 09:03
Show Gist options
  • Save non-static/7730191 to your computer and use it in GitHub Desktop.
Save non-static/7730191 to your computer and use it in GitHub Desktop.
def scope_test():
def do_local():
# print("before local " + spam)
spam = "local spam"
print("do_local: " + spam)
def do_nonlocal():
# print("before non-local: " + spam)
nonlocal spam
spam = "nonlocal spam"
print("do_nonlocal: " + spam)
def do_global():
# print("before global: " + spam)
global spam
spam = "global spam"
print("do_global: " + spam)
spam = "test spam"
print("original: " + spam)
print()
do_local()
print("After local assignment:", spam)
print()
do_nonlocal()
print("After nonlocal assignment:", spam)
print()
do_global()
print("After global assignment:", spam)
print()
#spam = ''
scope_test()
print("In global scope:", spam)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment