Python Namespaces are collections of different objects that are associated with unique names whose lifespan depends on the scope of a variable. The scope is a region from where we can access a particular object. There are three levels of scopes: built-in (outermost), global, and local. We can only access an object if its scope allows us to do so.
For example:
# global namespace
var_a = 75
def A_func():
# local namespace
var_b = 38
def B_inner_func():
# nested local
# namespace
var_c = 24
We cannot access the variable var_a if we refer to it in the nested local namespace (where var_c is present). If we try to assign a new value to var_a from here, a new variable gets created in the nested local namespace.
Related Questions
- How do you write first code in Python?
- How do you write an infinite loop in Python?
- How do you write a matrix in python?
- How do I write a Python script?
- Is while loop infinite Python?
- How do you write a 3×3 matrix in python?
- How do you create a namespace in Python?
- How do you make an infinite while loop?
- How do you create a matrix list in Python?
- What is datatype in Python?
- Which software is best for Python programming?
- Why is my FOR LOOP infinite Python?
- Which is not valid namespace in Python?
- How many datatypes are there in Python?
Related Topics
- Python Programming
- 9 Best Python IDEs and Code Editors
- Python Input-Output (I/O) Using input() and print() Function
- List of Keywords in Python Programming
- Python Keywords and Identifiers (Variable names)
- Python List Comprehension (With Examples)
- Python Looping Techniques
- Python Main Function
- Python Matrix and Introduction to NumPy
- Python Namespace and Scope of a Variable
- Python PIP
- Python Statement, Indentation, and Comments
- Python Type Conversion and Type Casting (With Examples)
- Python Variables, Constants, and Literals
- Python Data Types
Leave a Reply