Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of modifying Global variables inside python function

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report