Mark As Completed Discussion

What are namespaces in Python?

Before answering what namespaces are, let's quickly review some prior concepts. As you may remember, everything in Python is an object. Each object should have a unique name. For example, if you created a string for the word 'school':

PYTHON
1place = "school"

The string "school" is an object whose name is place. This object is stored with a specific address that points to its location in memory.

The answer to the question "what are Python namespaces?" will be more intuitive with this background. You can think of them as containers that inhabit these objects along with their names. Interesting! Let's dive deeper.

Namespaces

When we execute our program, namespaces are created. The name of each object acts as a key and the object itself as a value. Every function, module, or library has its own unique namespaces. If we import the NumPy library, then upon execution of our program, the Python interpreter will generate NumPy's namespace.