Python globals()

Python globals() builtin function is used to get global symbol table as a dictionary.

In this tutorial, we will learn about the syntax of Python globals() function, and learn how to use this function with the help of examples.

Syntax

The syntax of globals() function is

</>
Copy
globals()

Returns

The function returns a dictionary.

Example

In this example, we will get the global symbol table and print it to output.

Python Program

</>
Copy
result = globals()
print(result)

Output

{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x102807d60>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': '/Users/tutorialkart/Desktop/Projects/PythonTutorial/Example.py', '__cached__': None, 'result': {...}}

Conclusion

In this Python Tutorial, we have learnt the syntax of Python globals() builtin function, and also learned how to use this function, with the help of Python example programs.