Local vs non-local vars in a nested function

36 views Asked by At

Why the following code doesn't work as it is but would work after commenting either print(x) or x=1?

def f():
    x = 1

    def g():
        print(x)
        x = 1
    g()

f()
0

There are 0 answers