Changing global variable from a function
a = 42
def f():
global a
print(a)
a = 23
print(a) # 42
f() # 42
print(a) # 23
Does not need to be created outside
def f():
global a
a = 23
f()
print(a) # 23
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
a = 42
def f():
global a
print(a)
a = 23
print(a) # 42
f() # 42
print(a) # 23
Does not need to be created outside
def f():
global a
a = 23
f()
print(a) # 23