python local global variables code example
Example 1: python access global variable
globvar = 0
def set_globvar_to_one():
global globvar
globvar = 1
def print_globvar():
print(globvar)
set_globvar_to_one()
print_globvar()
Example 2: global var in python
a = input('Hello: ')
if a == 'world':
global b
b = input('Here')
print b
Example 3: python local variables
'''Local variables are those that are defined in a block '''
a = 1
def add():
b = 1
print(b)
add()
Example 4: global variables python
global x
x=1