rank_math_breadcrumb]
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.
Table of Contents
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()
Parameter:
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()
print(symbols)
Output
{'__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\\test.py', '__cached__': None, 'symbols': {...}}
Example 2:
x = globals()
print(x["__file__"])
print(x['__name__'])
print(x['__builtins__'])
Output
C:\Users\Vishvajit\Desktop\PF Article\Python Basic part1\test.py
__main__
<module 'builtins' (built-in)>
Conclusion
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