InterviewSolution
| 1. |
What are Python namespaces? Why are they used? |
|
Answer» A namespace in PYTHON ensures that object names in a program are unique and can be used without any conflict. Python implements these namespaces as dictionaries with 'name as key' mapped to a corresponding 'object as value'. This ALLOWS for multiple namespaces to use the same name and map it to a separate object. A few examples of namespaces are as follows:
The lifecycle of a namespace depends upon the scope of objects they are mapped to. If the scope of an object ends, the lifecycle of that namespace comes to an end. Hence, it isn't POSSIBLE to access inner namespace objects from an outer namespace. |
|