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

How does python view all variable names and values in the function body?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "python how to view the function body of all variable names and variable values", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "python how to view the function body of all variable names and variable values" bar!

The specific usage is analyzed as follows:

The function of the python eval () function: evaluates the string str as a valid expression and returns the result.

Syntax: eval (source [, globals [, locals]])-> value

Parameter description:

Source: a code object returned by a Python expression or function compile ()

Globals: optional. Must be dictionary

Locals: optional. Any map object

If the globals parameter is provided, it must be of type dictionary; if the locals parameter is provided, it can be any map object.

The global namespace of python is stored in a dict object called globals (); the local namespace is stored in a dict object called locals (). We can use print (locals ()) to see all the variable names and values in the body of the function.

Examples of use:

In [1]: eval ("1 + 3") Out [1]: 4 In [2]: eval ("(1 + 2) * 3") Out [2]: 9 In [3]: eval ("[1,2,3]") Out [3]: [1,2,3] In [5]: eval ("type ({'name':' zhangsan'})") Out [5]: dict thanks for your reading The above is the content of "how python views all variable names and variable values in the function body". After the study of this article, I believe you have a deeper understanding of how python views all variable names and variable values in the function body, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Internet Technology

Wechat

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

12
Report