Hello Everyone,
Can anyone tell me how to set a global variable inside a function in python? Also, check the below code or anyone knows the better way to learn python in depth. Any recommendation on below code is it right or not.
globvar = 0
def set_globvar_to_one():
global globvar # Needed to modify global copy of globvar
globvar = 1
def print_globvar():
print globvar # No need for global declaration to read value of globvar
set_globvar_to_one()
print_globvar() # Prints 1
Can anyone tell me how to set a global variable inside a function in python? Also, check the below code or anyone knows the better way to learn python in depth. Any recommendation on below code is it right or not.
globvar = 0
def set_globvar_to_one():
global globvar # Needed to modify global copy of globvar
globvar = 1
def print_globvar():
print globvar # No need for global declaration to read value of globvar
set_globvar_to_one()
print_globvar() # Prints 1