How does python find variable names
This article mainly introduces "how to find variable names in python". In daily operation, I believe many people have doubts about how to find variable names in python. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to find variable names in python". Next, please follow the editor to study!
1. Find the variable names from the inside out, which are Local, Enclosing, Global, and Builtin, respectively.
2. When accessing variables, first find the local variables, wrap the internal variables of the external function, then the global variables, and finally the built-in variables.
Example
In [11]: I = "G" In [12]: def test (): I = "L" print I, "in locals"....: In [13]: test () L in localsIn [14]: print I, "in globals" G in globals here, on "python how to find variable names" learning is over, hope 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!