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()