def myfunc(): x = 200 print(x) myfunc() #works #print(x) does not work #as a rule, you can use a variable more "outside" than you but you cannot use a variable more "inside".