ExamVeda
Login
Home
Introduction to Python
?

What is the order of namespaces in which Python looks for an identifier?

Answer & Solution
Correct Answer: Option B
When Python encounters an identifier (variable or function name), it searches for it in a specific order across different namespaces.
The order of namespaces that Python looks for an identifier is:
Built-in namespace: Python first searches the built-in namespace, which contains the names of all built-in functions, exceptions, and constants.
Local namespace: Next, Python searches the local namespace, which contains names defined within the current function or code block.
Global namespace: If the identifier is not found in the local namespace, Python searches the global namespace, which contains names defined at the top level of the current module or in the global scope.
If the identifier is not found in any of these namespaces, Python raises a NameError.
Therefore, the correct order of namespaces in which Python looks for an identifier is: built-in namespace, local namespace, global namespace.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Vaishali Gupta
Vaishali Gupta 7 months ago
order should follow
LEGB
L-Local
E- Enclosing
G- Global
B-Built in...
therefore option C should be correct