I'm relatively new to Python, so please forgive my ignorance.
I have two functions acting on a single variable var
:
var = 8
def func1():
print(var)
def func2():
var += 1
print(var)
func2
will not function unless I define var
as a global variable:
def func2():
global var
var += 1
print(var)
What is the functionality that allows me to call global variables (as in func1
) but does not allow me to redefine global variables without explicitly calling them first (as in func2
)?