Python globals() function
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
globals()
Parameter
NA
Return
This function returns the global symbol table as a dictionary.
Example 1
# 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
5