Sign in · Sign up

Lesson 6.6

A variable inside a function is local: it cannot be seen from outside.

x = 10

def show():
    y = 5
    print(x)    # 10 — the global one is visible inside
    print(y)    # 5

show()
print(x)        # 10

But print(y) outside raises a NameError: y lives only inside show.

The check sets two numbers outer and inner. Write a function show() that prints outer and inner, call it, and then print outer once more.

Hint

A function sees variables created outside.

Inside show() two print calls with the names outer and inner are enough. Right after the call to show(), print outer once more.