Chapter 10, Object-Oriented Programming 25
b. The local namespace exists from the moment the function or method is called
until it terminates and is accessible only to that function or method.
c. In a function’s or method’s suite, assigning to a variable that does not exist cre-
ates a local variable and adds it to the local namespace.
d. Identifiers in the local namespace are in scope from the point at which you de-
fine them until the program terminates.
10.15 Q3: Which of the following statements a), b) or c) is false?
a. Each module has a global namespace that associates a module’s global identifi–
ers (such as global variables, function names and class names) with objects. An
IPython session has its own global namespace for all the identifiers you create in
that session.
b. Python creates a module’s global namespace when it loads the module. A mod-
ule’s global namespace exists and its identifiers are in scope to the code within
that module until the program (or interactive session) terminates.
c. Each module’s global namespace also has an identifier called __name__ con-
taining the module’s name, such as ‘math’ for the math module.
d. All of the above statements are true.
10.15 Q4: When you use an identifier, Python searches for that identifier in the
currently accessible namespaces, proceeding from ________ to ________ to ________.
a. global, built-in, local
b. built-in, local, global
c. local, built-in, global
d. local, global, built-in
10.15 Q5: Which of the following statements a), b) or c) is false?
a. Python allows you to define nested functions inside other functions or methods.
b. If a function or method performs the same task several times, you might define
a nested function to avoid repeating code in the enclosing function.
c. When you access an identifier inside a nested function, Python searches the
nested function’s local namespace first, then the global namespace, then the built–
in namespace and finally the enclosing function’s namespace —this is sometimes
referred to as the LGBE (local, global, built-in, enclosing) rule.
d. All of the above statements are true.