Globals() method in Python Built in Function
globals method in built in function returns the current global symbol table as dictionary.
A symbol table is nothing but a data structure which is maintained by a compiler which contains all the necessary information required by a program. The table contains variable names, methods, classes etc.
The symbol table is of 2 types
- Local symbol table: it stores all the information related to the local scope of the program. This is accessed in python using the local method.
- Global symbol table: it stores all the information related to the global scope of the program. This is accessed in python using the globals method.
Syntax:
Globals()
Parameters
Globals so not have any parameters.
Example-1:
Without adding variable
x = globals()
Output:

Example-2:
By adding variable
age = 24
globals()['age'] = 30
print('The age is:', age)
Output:
