Setting a Local Python Variable to be Global
Python - General Python
We can set a local variable (i.e. one in a function) to be global by using the global keyword. This allows a global variable to be modified from within a non-global space or a local variable to be accessible outside the scope of the local space it's declared within.
def some_function() global variable_name variable_name = 'New Value' #Example: number = 42 def new_number(): global number number = 43 new_number()
By GregHe1979 - Last Updated Sept. 8, 2021, 10:13 p.m.