Definition

All entities in Python are considered objects. Every object, including variables, classes, and functions, is given a name for identification purposes. These names are frequently referred to as identifiers in python namespace. Therefore, the name is merely an identifier. These names and the locations where they are used are each stored in main memory at a distinct location. This region is referred to as space. Python namespace refer to the location allocated to an object name and its value. Python additionally maintains a namespace known as a python dictionary. All Python namespace are similar to dictionaries, where names serve as keys and dictionary values are the actual values associated with those names.

Python namespace Example

A computer system's file directories are the best example of namespaces. Files with identical names but distinct contents are stored in various locations. If we know the file's exact address, we can locate it precisely. The telephone directory is a good example of the namespace in real life. There are multiple entries for the phone number of a person named John, making it difficult to find the correct one. However, if we know John's surname, we can see the correct number. In this instance, a person's name is a name or identifier in Python, and the location of the person determines the amount of space.

Integrated Namespace

Some functions, including input(), print(), and type(), are always present when the Python interpreter is run without any user-defined functions, classes, or modules. These are Python's built-in namespaces.

Global Namespace

When a module is created, its namespaces are created; these are known as global namespaces. The global namespace can access namespaces that are predefined.

Local Namespace

When a function is created, it generates its own namespaces, known as local namespaces. A local namespace has access to both global and internal namespaces.