Menu Close

Python globals() Function


In this tutorial guide, we are going to learn all about the python globals function to find the globals symbol table as a dictionary.
globals() is the best built-in function to find the globals symbols symbol. In the previous tutorial, we have seen Python getattr function to find the value specified attribute of the specified object.

Python globals() Function

Python globals function is a Python built-in function that is used to find the global symbol table as a dictionary.

The syntax of global function in Python is:-



globals function in python does not support any parameter.

Return Value

Return value of globals function in python is:-

Python globals() example

Here we will use python globals function along with example.

Example 1:

symbols = globals()


{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x0000019202190AF0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'C:\\Users\\Vishvajit\\Desktop\\PF Article\\Python Basic part1\\', '__cached__': None, 'symbols': {...}}

Example 2:

x = globals()


C:\Users\Vishvajit\Desktop\PF Article\Python Basic part1\
<module 'builtins' (built-in)>


So, In this tutorial, you have learned all about Python globals function to find the symbols as a dictionary. If this article helps you, please keep visiting for further python built-in functions tutorials.

Python built-in functions

For more information:- Click Here

Previous Article
Next Article

Related Posts