The globals() function in Python returns the current global symbol table as a dictionary object.
Python maintains a symbol table to keep all necessary information about a program. This info includes the names of variables, methods, and classes used by the program.
All the information in this table remains in the global scope of the program and Python allows us to retrieve it using the globals() method.
Signature: globals()
Arguments: None
# Example: globals() function
x = 9
def fn():
y = 3
z = y + x
# Calling the globals() method
z = globals()['x'] = z
return z
# Test Code
ret = fn()
print(ret)
The output is:
12