top of page
Search
Writer's pictureMayuri Kale

Namespaces in Python




In simple words, A namespace is a collection of names and the details of the objects substantiated by the names. We can consider a namespace as a python wordbook which maps object names to objects. The keys of the wordbook correspond to the names and the values write to the objects in python.


Namespaces in python are one honking great idea — let’s do further of those! Namespaces are the constructs used for organizing the names charged to the objects in a python program. In this composition, we will decide the conception of names and namespace in python.


Local Namespace

This namespace includes local names inside a function. This namespace is created when a function is called, and it only lasts until the function returns.

A local namespace is defined for a class, a function, a circle, or any head of code. The names defined in a block of law or a function are local to it. The variable names can not be penetrated outside the block of code or the function in which they're defined. The local namespace is created when the block of law or the function starts executing and terminates when the function or the head of code terminates.


Global Namespace

This namespace includes names from colorful imported modules that you're applying in a arrangement. It's created when the module is included in the design, and it lasts until the script ends.


Built-in Namespace

This namespace includes set up-in functions and built-in exception names.

In the Mathematical Modules in Python series on Envato Tuts, I scratched about useful fine functions available in different modules.


For illustration, the calculation and cmath modules have a lot of functions that are common to both of them, like log10 (), acos (), cos (), exp (),etc.However, the only way to use these functions unambiguously is to prefix them with the name of the module, like calculation, If you're using both of these modules in the sameprogram.log10 () andcmath.log10 ().



8 views0 comments

Comments


Post: Blog2_Post
bottom of page