Get the App
SLTechnology News&Howtos  ›  Development  › 

Creation and Modification of global in python

Shulou Source: shulou.com Published: 2022-06-03 15:33:31 11月14日 Update

This article mainly introduces "the creation and modification of global in python". In the daily operation, I believe that many people have doubts about the creation and modification of global in python. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the creation and modification of global in python". Next, please follow the editor to study!

1. Global creates a global variable in a function, which is equivalent to creating a global variable in a file.

2. Modify the global variables in the function. Because global variables are assigned / modified directly in the function, they are considered to create new local variables.

Of course, you can modify it by indexing the elements in the global variable.

Example

Global variable 1, variable 2,... Variable 1 = assignment data # error demonstration Global variable 1 = data # python believes that a local variable has been created: variable 1. # correctly demonstrate the global variable that global expects to modify 1 # first tell python that this variable is also treated as a global variable in this part. It is expected that the modified global variable 1 = data is over, and the study on "creation and modification of global in python" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Variables global learning function local data expectations more help demonstration practical and then elements can be passed through examples files articles methods theories knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi MariaDB Huawei Shulou Information