首頁 >後端開發 >Python教學 >Python內建globals函數的詳細介紹

Python內建globals函數的詳細介紹

高洛峰
高洛峰原創
2017-03-21 11:04:141945瀏覽

英文文件:

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


  • #說明:

  •   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