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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -