# basics functions

Local vs. Global Variables

A variable created inside a function only exists inside it — that's called being local. A variable with the same name outside the function is a completely separate thing:

x = 10

def show_local():
    x = 5
    print(x)

show_local()
print(x)

prints:

5
10

The x inside show_local never touches the x outside it.

Your turn: the global x = 50 is given. Define show_local() that creates its own local x = 7 and prints it. Call show_local(). Then print the global x again — it should still be 50.

💡 need a hint?

pyb-func-scope.py🔒 given lines are locked — write your code in between
loading...