What are python namespaces in python language
A Python namespace ensures that object names in a program are unique and can be used without any conflict. Python implements these namespaces as dictionaries with ‘name as key’ mapped to its respective ‘object as value’.
Let’s explore some examples of namespaces:
- Local Namespace consists of local names inside a function. It is temporarily created for a function call and gets cleared once the function returns.
- Global Namespace consists of names from various imported modules/packages that are being used in the ongoing project. It is created once the package is imported into the script and survives till the execution of the script.
- Built-in Namespace consists of built-in functions of core Python and dedicated built-in names for various types of exceptions.