PHP前端开发

Python内置globals函数的详细介绍

百变鹏仔 3小时前 #Python
文章标签 详细介绍

英文文档:

  • 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. 返回当前作用域内全局变量的字典。

&gt;&gt;&gt; globals(){'__spec__': None, '__package__': None, '__builtins__': <module>, '__name__': '__main__', '__doc__': None, '__loader__': <class>}&gt;&gt;&gt; a = 1&gt;&gt;&gt; globals() #多了一个a{'__spec__': None, '__package__': None, '__builtins__': <module>, 'a': 1, '__name__': '__main__', '__doc__': None, '__loader__': <class>}</class></module></class></module>