Local and global variables of PYTHON functions, python global variables
With such a piece of PYTHON code, anyone who is engaged in C Language Development knows that if global variables are defined and function variables with the same name are not defined in the function, the value assigned to the variable in the function is the modification of the Space Value of the global variable,
But they are different in PYTHON. in python functions, if they are not explicitly declared as global variables, python will create local variables for the functions, therefore, the variable operated in the function is also a local variable.
Count = 5def myfun (): count = 10 print (count) myfun () print (count)
The printed result is as follows:
Then, how can we modify the value of the global variable in the function? Here we use a keyword: global. modify the code as follows to get the correct value.
Count = 5def myfun (): global count = 10 print (count) myfun () print (count)