In this tutorial we will learn about python globals() method and its uses with examples.

What is Python globals() Method?
The globals() method returns the dictionary of the current global symbol table.
What is the symbol table in python?
A symbol table is a data structure that contains all the necessary information regarding the program that includes variable names, functions, methods, classes, etc.
The syntax of globals() method is:
globals() Parameters
The globals() method does not take any parameter.
Let us check some examples of globals() method.
If we use the globals() method in the python interpreter, it will show as all the global variables and other default symbols declared by python.
Example 1: Using globals() with python interpreter.
When you run the above program, it will display the following output on the python interpreter.
Output:
Example 2: How to use globals() method in python?
Output:
We can also modify the global variable using the globals() method.
Example 3: Modify global variable using globals() method.
The output will be as follow:
We can also check global variables of other python libraries using the globals() method.
Example 4: using globals() method with python libraries.
The output will be as follow:
As you can see, it returns all the global variables and default symbols of imported python libraries.
Rules of Python globals()
The globals() method returns the result in dictionary format of the current global symbol table.