Python Namespaces and Scope

Python Namespaces is a way that make sure that object names are unique and can be used without any conflict.Python maintain namespace in the form of dictionary with ‘name as key’ mapped to a corresponding ‘object as value’.

Realtime example for namespace is their may be multiple employee with same name John ,but if we specifically identify John emp1009 their will only one person.The same way based on the namespace Python interpreter understands what exact method is trying to point to in the code.

Types of namespaces in Python

Local Namespace : Local Names space is created inside a function and gets cleared when the function returns.so it is temporary created inside the functions when it is called and cleared when the function returns

Global Namespace : Global Namespace are the namespace from imported module or package .The namespace are created when the package is imported in the script and it will be last long until until the execution of the script.

Built-in Namespace : includes built-in functions and the built-in names for various types of exceptions.

Lifecycle of a Namespaces purely depend on the scope of the object the mapped are mapped to it.

Python Namespaces

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator