Xiaoyu SONG My personal Blog | Xiaoyu SONG

<< All Blogs

Python Study note

When we import a module, we add all of the objects and functions within that module to the global namespace.

A namespace is a dictionary that contains all of the names we can refer to in our code.

Before running our code, the Python interpreter adds all of the objects and functions that are available by default (print(), list(), etc.) to the global namespace. When we create variables or define our own functions, these are also added to the same namespace.

When we import an entire module, we’re adding everything within that module into the global namespace, prefixed by the module name: