Python globals() function
Published February 16, 2022The Python globals() function is a built-in function that updates and returns the current global symbol table dictionary. It is common in programming to store global variables and functions that are not associated with a certain class or function. Debugging and discovering which items are in the global scope are the primary functions of this method.
What is a symbol state?
A symbol state is a data structure containing all of the program's critical information. This information comprises classes, methods, names, and so forth.
What is a global symbol table?
A global symbol table holds all of the critical information about the program's global scope and may be retrieved using the function globals ().
Syntax
The syntax for the globals () method is as follows.
Syntax: globals() |
There are no parameters needed.
Let's take a look at the example below
Example
x = 3 def func(): y = 7 z = x * y globals()['x'] = z print(z) func() |
Output
21 |
Article Contributed By :
|
|
|
|
325 Views |