Tags
python
Asked 2 years ago
9 Aug 2021
Views 248
Domenic

Domenic posted

what is globals() in Python ?

what is globals() in Python ?
fatso

fatso
answered Aug 9 '21 00:00

globals()
Return a dictionary representing the current global symbol table.




print(globals())


it will print

{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7fba730c2af0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'globals.py', '__cached__': None}


lets print lists of globals() function :


print(lists(globals()))


it will show like this

['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', '__file__', '__cached__']

steave

steave
answered Aug 9 '21 00:00

locals() and globals() return same dictionary .


print(locals()==globals())


it will print True
Post Answer