foo.bar.nonlocal example

This commit is contained in:
Mert Gör 🇹🇷 2023-06-04 21:00:55 +03:00
parent c6f5c580a3
commit c8bb84641a
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,12 @@
def foo():
x = 10
def bar():
nonlocal x # foo'daki x
x = 20
def tar():
nonlocal x # bar'daki x
x = 30
tar()
bar()
print(x) # 30
foo()

View File

@ -0,0 +1,12 @@
def foo():
x = 10
def bar():
nonlocal x # foo'daki
x = 20
def tar():
nonlocal x # bar'daki x
x = 30
tar()
bar()
print(x)
foo()