Home / Python Tips Generated By ChatGPT / Using global and nonlocal in Python Modify variables outside of the current scope. Source Code x = 0 def outer(): x = 1 def inner(): nonlocal x x = 2 print("inner:", x) inner() print("outer:", x) outer() print("global:", x)