how to make variable global in python
global variable
variable = 'whatever'
how to make variable global in python
global variable
variable = 'whatever'
python access global variable
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
global variable python
#it is best not to use global variables in a function
#(pass it as an argument)
a = 'This is global a'
def yourFunction():
global a
return a[0:2]
global variable python
a = 0
def testFor():
global a
if(a == 0):
#run code
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us