Drag a concept onto its matching description — or click a concept then click the description.
Inside a function
At module level
In outer function (nested)
Predefined names in Python
Variable from enclosing scope (not global)
Match each variable scope to its description.
Drag a concept onto its matching description — or click a concept then click the description.
Inside a function
At module level
In outer function (nested)
Predefined names in Python
Variable from enclosing scope (not global)
Answer choices
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
Local: Variables defined inside a function.
The LEGB rule defines scope lookup order: Local, Enclosing, Global, Built-in. Correct matches are Local (inside function), Enclosing (outer function), Global (module level). Built-in consists of Python's predefined names.
Answer analysis
For each option: why learners choose it and why it is or isn't the right answer here.
Local: Variables defined inside a function.
Why this is correct
A local variable is created when a function is called and exists only within that function's own namespace. In Python's LEGB scope resolution, 'Local' is the innermost scope, taking precedence over enclosing, global, and built-in names. Because it is destroyed when the function returns, it cannot be referenced elsewhere without raising a NameError.
Enclosing: Variables in the outer function (nonlocal).
Why this is correct
An enclosing scope is the outer function in a nested function relationship. When an inner function needs to read a variable from that outer function, Python resolves it via the 'E' in LEGB before falling back to global or built-in. To reassign such a variable from inside the inner function, you must declare it with the nonlocal keyword to avoid creating a new local variable.
Global: Variables defined at the top level of a module.
Why this is correct
A global variable is defined at the top level of a module, outside any function or class. It belongs to the module's global namespace and is accessible from any function defined in that module. If a function assigns to a global variable without a global declaration, Python treats the name as a new local variable, so the global keyword is required for such assignment to affect the module-level variable.
Built-in: Variables defined at the top level of a module.
Why it's wrong here
Built-in scope comprises the names that Python itself predefines before any user code runs, such as print, len, and range. Saying built-in variables are defined at the top level of a module conflates two distinct namespaces; top-level assignments belong to the global scope. The built-in scope is actually populated by the builtins module and is consulted last by LEGB resolution, providing a fallback for common functions.
Local: Variables defined in an enclosing function.
Why it's wrong here
A variable defined in an enclosing (outer) function is not local to the inner function; it lives in the enclosing scope, which is a separate scope between local and global. Local scope refers only to the current, innermost function body. Even if the inner function can read the outer function's variable, that variable is still categorically an enclosing variable, and modifying it requires the nonlocal declaration.
Global: Predefined names like print and len.
Why it's wrong here
Predefined names like print and len are built-in names, not global variables. In Python's scope model, the global scope is the module's own namespace, while built-in names occupy a dedicated scope that is implicitly available everywhere. The confusion often arises because built-ins are accessible from anywhere and appear 'global,' but they are managed differently and are stored in builtins, not in your module's global dictionary.
Go deeper
About these practice questions
Courseiva writes every PCAP question from scratch — 421 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.