首页 >后端开发 >Python教程 >Python内置globals函数的详细介绍

Python内置globals函数的详细介绍

高洛峰
高洛峰原创
2017-03-21 11:04:141954浏览

英文文档:

  • globals()

  • Return a dictionary representing the current global symbol table. This is always the dictionary of the current module (inside a function or method, this is the module where it is defined, not the module from which it is called).


  • 说明:

  •   1. 返回当前作用域内全局变量的字典。

>>> globals()
{&#39;__spec__&#39;: None, &#39;__package__&#39;: None, &#39;__builtins__&#39;: <module &#39;builtins&#39; (built-in)>, &#39;__name__&#39;: &#39;__main__&#39;, &#39;__doc__&#39;: None, &#39;__loader__&#39;: <class &#39;_frozen_importlib.BuiltinImporter&#39;>}
>>> a = 1
>>> globals() #多了一个a
{&#39;__spec__&#39;: None, &#39;__package__&#39;: None, &#39;__builtins__&#39;: <module &#39;builtins&#39; (built-in)>, &#39;a&#39;: 1, &#39;__name__&#39;: &#39;__main__&#39;, &#39;__doc__&#39;: None, &#39;__loader__&#39;: <class &#39;_frozen_importlib.BuiltinImporter&#39;>}

以上是Python内置globals函数的详细介绍的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn