The global Keyword in Python


Declare variables inside functions as global to modify the global scope.

Source Code

x = 5
def change_global_x():
    global x
    x = 10
change_global_x()
print(x)  # 10
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments