What are python namespaces?

A Python namespace guarantees that in a programme, object names are unique and may be used without conflict. These namespaces are implemented as dictionaries, with the key “name” mapped to the value “object.”

Let’s look at several namespace examples:

  • 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.