
Python InstitutePCAP - Certified Associate Python Programmer
Domain 5Objective 3
PCAP-31-03 5.3 Define and Use Closures PCAP-31 Practice Questions (Page 1)
Part of the Miscellaneous (List Comprehensions, Lambdas, Closures, I/O) domain, which accounts for 22% of the PCAP-31 exam. Python Institute does not publish an official question count, but from its 65-minute exam (~25–45 total, ~6–10 in this domain), expect 1–2 from this objective — we provide 7 practice questions to prepare you well beyond it. (estimate)
7questions here
2free pages
3concepts
22%of the exam
Questions 1–5
- 1
Consider the following code: def counter(): count = 0 def increment(): nonlocal count count += 1 return count return increment c = counter() print(c()) print(c()) print(c())
Select an answer first - 2
A developer is debugging a closure that does not behave as expected. The code is: def create_functions(): funcs = [] for i in range(3): def f(): return i funcs.append(f) return funcs for func in create_functions(): print(func(), end=' ') What is the output?
Select an answer first - 3
A developer is designing a system where multiple event handlers need to share a common state, but each handler must also have its own private state. The developer considers using closures. What is the most appropriate way to achieve this?
Select an answer first - 4
A developer is building a logging utility for a multi-module application. Each module must maintain its own independent message counter, and the counter must persist between log calls without using global variables. The developer writes a function that returns a nested function, capturing a counter variable from the enclosing scope. What is the primary benefit of this approach?
Select an answer first - 5
A developer is implementing a rate limiter for an API client. The limiter must track the number of requests made in the current minute and reset the count when a new minute begins. The developer writes the following closure: def rate_limiter(limit): count = 0 def check(): nonlocal count if count >= limit: return False count += 1 return True return check allow = rate_limiter(3) print(allow(), allow(), allow(), allow()) What is the output?
Select an answer first
Finished these 5 questions?
Review the revealed explanations, or continue through the curriculum.
Free Basic Practice is a study aid with revealable answers — not a scored exam. Examers.io is independent and not affiliated with or endorsed by Python Institute. “PCAP-31” is a trademark of its owner, used for identification only.