Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python find variable names

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

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!

Tags: Variables learning functions more help practical next from the inside out global package examples articles methods theories knowledge articles websites materials follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Huawei Redmi MySQL