Python globals() function
The globals() function in Python returns the value of the named attribute of object where the ‘name’ must be a string.
Syntax
1 2 3 |
globals() |
Parameter
NA
Return
This function returns the global symbol table as a dictionary.
Example 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Python program explaining # the globals() function # global variable x = 15 def Sub(): y = 10 z = x - y # using globals() function globals()['x'] = z print (z) # Driver Code sub() |
Output
1 2 3 |
5 |