python class access global variable 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: python local variables
'''Local variables are those that are defined in a block '''
a = 1
def add():
b = 1
print(b)
add()
Example 3: global var in python
a = input('Hello: ')
if a == 'world':
global b
b = input('Here')
print b
Example 4: global variables python
global x
x=1
Example 5: how to declare global variable in python
global n
n = 'whatever'