Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python globals() function returns the global table dictionary. The table contains all the necessary information about the current program.

Syntax

globals()

Parameters

No parameter is required.

Example:

In the below example, the globals() is used to return the current global table dictionary.

x = globals()
print(x)

The output of the above code will be:

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

Example:

The globals() function can also be used to retrieve only required information about the current program. Like in the below example, it is used to retrieve the name of the current program only.

x = globals()
print(x["__name__"])

The output of the above code will be:

__main__

❮ Python Built-in Functions

5