nonlocal and variable

This commit is contained in:
Mert Gör 🇹🇷 2023-06-04 14:07:08 +03:00
parent 247ebeb4e5
commit a5d6ac70f4
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,11 @@
x = 10
def foo():
def bar():
#nonlocal x #error!
#print(x)
x = 20
print(x)
bar()
foo()

View File

@ -0,0 +1,11 @@
x = 10
def foo():
def bar():
nonlocal x #error!
print(x)
x = 20
print(x)
bar()
foo()