
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
What is a namespace in Python?
Namespace is a way to implement scope. In Python, each package, module, class, function and method function owns a "namespace" in which variable names are resolved. When a function, module or package is evaluated (that is, starts execution), a namespace is created. Think of it as an "evaluation context". When a function, etc., finishes execution, the namespace is dropped. The variables are dropped. Plus there's a global namespace that's used if the name isn't in the local namespace.
Each variable name is checked in the local namespace (the body of the function, the module, etc.), and then checked in the global namespace.
Variables are generally created only in a local namespace. The global and nonlocal statements can create variables in other than the local namespace.
- Related Articles
- What is "namespace" keyword in PHP?
- What is global namespace pollution in JavaScript?
- How do I create a Python namespace?
- How do I create a namespace package in Python?
- What is the equivalent of C# namespace in Java?
- Explain python namespace and scope of a variable.
- How to create python namespace packages in Python 3?
- Extending namespace and Unnamed namespace
- How to import everything from a python namespace / package?
- Namespace in C++
- Docker Container Network Namespace Is Invisible
- System.Reflection namespace in C#
- How do I import all the submodules of a Python namespace package?
- How do I declare a namespace in JavaScript?
- How to make a namespace in Lua programming?
