Created
December 1, 2013 09:03
-
-
Save non-static/7730191 to your computer and use it in GitHub Desktop.
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 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