Python: do variable assignments from the global environment interact with variables inside function definitions? -
this function shows value of variable "a" inside function influenced value of "a" in global environment
a=1 def f(x): print(a) return x+a f(3)
the output 4 , printed value of 1. understanding of functions in python, global environment separate local environment (inside function), cannot explain why value of 1 inside function. please explain. appreciated.
ps: first post on stack overflow, please excuse style of asking if it's not liking.
Comments
Post a Comment