{"id":24817,"date":"2021-11-02T09:48:08","date_gmt":"2021-11-02T04:18:08","guid":{"rendered":"https:\/\/python-programs.com\/?p=24817"},"modified":"2021-11-05T20:37:13","modified_gmt":"2021-11-05T15:07:13","slug":"python-globals-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-globals-function-with-examples\/","title":{"rendered":"Python globals() Function with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python filter() Function with Examples<\/a>
\n globals() Function in Python:<\/strong><\/p>\n

The globals() function returns a dictionary containing the global symbol table.<\/p>\n

A symbol table contains information about the current program that is required.<\/p>\n

Variable names, methods, classes, and so on are examples of this.<\/p>\n

There are two types of symbol tables.<\/p>\n

    \n
  1. Local symbol Table<\/li>\n
  2. Global symbol Table<\/li>\n<\/ol>\n

    The local symbol table stores all information related to the program’s local scope and is accessed in Python via the locals() method.<\/p>\n

    The local scope could be within a function, a class, or something else.<\/p>\n

    Similarly, a Global symbol table stores all information related to the program’s global scope and is accessed in Python via the globals() method.<\/p>\n

    All functions and variables that are not associated with any class or function are included in the global scope.<\/p>\n

    Syntax:<\/strong><\/p>\n

    globals()<\/pre>\n

    Parameter Values: <\/strong>The globals() method does not accept any parameters.<\/p>\n

    Return Value:<\/strong><\/p>\n

    This method returns the dictionary containing the current global symbol table.<\/p>\n

    globals() Function with Examples in Python<\/h2>\n