Namespaces In Python

Anurag Verma
2 min readJul 12, 2021

Introduction

In this article, we are going to know about the namespaces in python, kinds of namespaces, and scopes in python. In python shows, everything is thought about an object. Call is nothing but the identifier of an item. And area is an address in the main memory related to that item. We can specify namespace as a collection of names related to the address in the main memory. There are 3 types of namespaces, Integrated Namespace, Global Namespace, and Regional Namespace. Each lower namespace can access the upper namespaces. And the scope of variables in python depends on the namespaces.

Namespace in Python
Every entity in python is thought about an object. We provide some names to every item like variable, class, and function for identification. Typically these names are known as identifiers. So, the name is nothing but the identifier. All these names and where we utilize value are saved in the main memory at an unique place. This place is referred to as space. So the area assigned to a things name and its value is referred to as a namespace in python. Python likewise maintains its namespace that is known as a python dictionary. All namespaces in python resemble dictionaries in which names are considered as secrets, and dictionary values are the real values associated with those names.

<h2>Scopes in Python</h2>
The life time of the object depends on the scope of the item. When the lifetime of the item comes to the end scope of variable in python likewise ends. Scopes in python are nothing but the part or part of the program where namespace can be accessed directly. If we produce a variable inside the function, then the scope of variable in python is regional. If we create a variable inside the module, then that variable has a global scope in python. And when we do not create any module or user-defined function and still can access the methods like print(), type(), input(), then it is a built-in scope.

Summary

In this post, we have learned about namespaces and scope in python. Also, we have learnt more about the kinds of namespace in python with examples. In python programs, whatever is considered an item. Name is nothing but the identifier of a things. And space is an address in the main memory associated with that item. We can define namespace as a collection of names connected with the address in the main memory. There are three kinds of namespaces, Built-in Namespace, Global Namespace, and Regional Namespace. The scope of variable in python is associated with the namespace in python.

--

--