
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
What are Python namespaces all about?
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 non-local statements can create variables in other than the local namespace.
- Related Articles
- What are namespaces in C#?
- What are nested namespaces in C#?
- Namespaces and Scoping in Python
- Namespaces and Scope in Python
- What is difference between builtin and globals namespaces in Python?
- What is The Prelude all about?
- What are some things one may dislike about Python?
- What was the Bubonic Plague all about?
- What is the Mohu Airwave all about?
- All About Laxatives
- How will you explain Python namespaces in easy way?
- How will you compare namespaces in Python and C++?
- How to generate XML documents with namespaces in Python?
- What is the Jaipur Literature Festival all about?
- What are all the common undefined behaviours that a C++ programmer should know about?
