Home  >  Article  >  Backend Development  >  Detailed introduction to Python’s built-in globals function

Detailed introduction to Python’s built-in globals function

高洛峰
高洛峰Original
2017-03-21 11:04:141876browse

English documentation:

  • 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 ).


  • ##Description:

  • ## 1 . Returns a dictionary of global variables in the current scope.
  • >>> 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;>}

The above is the detailed content of Detailed introduction to Python’s built-in globals function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn