This function shows that the value of variable "a" inside the function is influenced by the value of "a" in the global environment
a=1
def f(x):
print(a)
return x+a
f(3)
The output that I get is 4 and the printed value of a is 1. From my understanding of functions in python, the global environment is separate from the local environment (inside the function), so I cannot explain why the value of a is 1 inside the function. Could somebody please explain. Much appreciated.
PS: this is my very first post on Stack overflow, so please excuse my style of asking if it's not to your liking.