Skip to content

Instantly share code, notes, and snippets.

@kemingy
Last active July 16, 2020 12:09
Show Gist options
  • Save kemingy/0bf6255b44440273dcda8bcae772fc8d to your computer and use it in GitHub Desktop.
Save kemingy/0bf6255b44440273dcda8bcae772fc8d to your computer and use it in GitHub Desktop.
global nonlocal variables
x = 233
def xxx():
x = 222
def foo():
nonlocal x
x = 1
def bar():
nonlocal x
x = 123
print(x)
bar()
print(x)
foo()
xxx()
print(x)
x = 233
def foo():
global x
x = 1
def bar():
nonlocal x # SyntaxError: no binding for nonlocal 'x' found
x = 123
print(x)
bar()
print(x)
foo()
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment