Namespaces have different lifetimes, because they are often created at different points in time.
📌 The namespace containing the built-in names is created when the Python interpreter starts up, and is never deleted.
📌 The global namespace of a module is generated when the module is read in. Module namespaces normally last until the script ends, i.e. the interpreter quits.
📌 When a function is called, a local namespace is created for this function. This namespace is deleted either if the function ends, i.e. returns, or if the function raises an exception, which is not dealt with within the function.
source
Post #99
468
PyNotes Title: Namespaces A namespace is a system that has a unique name for each and every object in Python. An object might be a variable or a method. There are 3 types of namespaces: built-in namespaces global namespaces local namespaces e.g var1 = 5 # global…python-course.eu 27. Namespaces | Python Tutorial | python-course.eu Introduction into Namespaces and Scopes in Python