You can modify a global variable from within a function with a global statement.
_Note: this isn’t done very often. It’s better to be able to treat functions as black boxes.
def spam():
global eggs # <- global statement
eggs = 'spam'
eggs = 'global'
spam()
print(eggs)
Output:
spam