- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How will you explain Python namespaces in easy way?
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
- How will you compare namespaces in Python and C++?
- How will you compare modules, classes and namespaces in Python?
- How will you explain Python Operator Overloading?
- How to use pip to install python modules in easy way?
- How to add mixed fractions in an easy way?
- How will you explain Python for-loop to list comprehension?
- How will you explain that an exception is an object in Python?
- Easy way to re-order columns in MySQL?
- Snagit Tool: Taking Better Screenshots the Easy Way
- Namespaces and Scoping in Python
- Namespaces and Scope in Python
- Easy way to remember Strassen's Matrix Equation in C++
- How to generate XML documents with namespaces in Python?
- How you will create your first program in Python?
- How will you handle alerts in Selenium with python?
