Python Namespace

Namespaces in Python

A namespace is a system that has a unique name for each and every object in Python. An object might be a variable or a system. Python itself maintains a namespace in the form of a Python wordbook.

When Python exponent runs solely without any stoner- defined modules, styles, classes, etc. Some functions like print (), id () is always present, these are erected-in namespaces. When a stoner creates a module, a global namespace gets created, latterly the creation of original functions creates the original namespace. The erected-in namespace encompasses the global namespace and the global namespace encompasses the original namespace.

Not every namespace, which may be used in a script or program is accessible (or alive) at any moment during the accomplishment of the script. Namespaces have different durations, because they're frequently created at different points in time. There's one namespace which is present from beginning to end. The namespace containing the constructed-in names is created when the Python practitioner starts up, and is no way deleted.

Namespaces in Python are applied as Python wordbooks, that is, they're defined by a mapping of names, i.e. the keys of the wordbook, to objects, i.e. the values. The doper does not have to know this to write a Python program and when using namespaces.

Global Namespace

The global namespace of a module is generated when the module is read in. Module namespaces typically last until the script ends, i.e. the practitioner quits. When a function is called, a original namespace is created for this function. This namespace is deleted either if the function ends, i.e. returns, or if the function raises an exception, which isn't dealt with within the function.

Built- in namespace

Built- in namespace contains the names of built-in functions and objects. It's created while starting the python practitioner, exists as lengthy as the exponent runs, and is destroyed when we close the exponent. It contains the names of built-in data types, exceptions and functions like print () and input ().