Home > Backend Development > Python Tutorial > Detailed introduction to Python's built-in globals function

Detailed introduction to Python's built-in globals function

高洛峰
Release: 2017-03-21 11:04:14
Original
1971 people have browsed it

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;>}
    Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template