MOHOSHA
MOHOSHA

Reputation: 99

Local vs non-local vars in a nested function

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

Upvotes: 0

Views: 34

Answers (0)

Related Questions