global scope python 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 variable python
a = 0
def testFor():
global a
if(a == 0):
Example 3: how does scope work in python
a = 5
b = 3
def f1():
a = 2
print(a)
print(b)
print(a)
f1()
Example 4: python variable scope
a = 5
def f1():
a = 2
print(a)
print(a)
f1()
Example 5: python globals
globals 1, 2, 3