Example Analysis of modifying Global variables inside python function
This article mainly introduces the python function internal modification of global variables example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.
1. To point global variables to different objects, you need to use the global keyword.
Def change_global_variable (): global global_variable global_variable = 'Bar'
2. Note that after writing this function, the code that actually changed it is still not running.
> use_global_variable () 'Footwood financing' > change_global_variable ()
3. After calling the function, you can see that the global variable has changed. The global_variable name now points to 'Bar'.
> use_global_variable () 'bargaining rooms'
Note that the "global" in Python is not really global-it's just a module-level global. So it only applies to functions written in modules that are global. Functions remember the modules that wrote them, so when they are exported to other modules, they still look for global variables in the module in which they were created.
Thank you for reading this article carefully. I hope the article "sample Analysis of modifying Global variables within python function" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!