In Python, "variables" are really "names" and you can access them whenever they're in scope!
However, if you intend to modify a name that's outside of the current scope, you need to tell the interpreter so (otherwise it'll assume that you mean to give the name to something else within your scope)
a = None
def foo():
# you can access a, but not set it here
print(a)
a = None
def foo():
a = 1 # a is only set within foo
print(a) # refers to a in outer scope
usage of global
a = None
def foo():
global a
# now you can modify a
a = 1
creates an error
a = None
def foo():
print(a)
global a # SyntaxError: name 'a' is used prior to global declaration