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

Questions & AnswersCategory: Programming LanguageWhat is the order of namespaces in which Python looks for an identifier?
Geek Boy Staff asked 2 years ago

What is the order of namespaces in which Python looks for an identifier?
a. Python first searches the built-in namespace
then the global namespace and finally the local namespace
b. Python first searches the built-in namespace
then the local namespace and finally the global namespace
c. Python first searches the local namespace
then the global namespace and finally the built-in namespace
d. Python first searches the global namespace
then the local namespace and finally the built-in namespace

1 Answers
Geek Boy Staff answered 2 years ago

c. Python first searches the local namespace, then the global namespace and finally the built-in namespace
Explanation: Python first searches for the local, then the global and finally the built-in namespace.