python access variable outside function code example
Example 1: global variable python
a = 0
def testFor():
global a
if(a == 0):
#run code
Example 2: global variables python
global x
x=1
Example 3: accessing a variable from outside the function in python
# for accessing a variable from outside the function then create that variable
# as an attribute of the function
def hi():
# other code...
hi.bye = 42 # Create function attribute.
sigh = 10
hi()
print(hi.bye) # -> 42