Python Institute PCPP1 sample questions with explanations, traps, topic labels, and IT Mastery route links.
These original sample questions are designed to help you check how the exam topics appear in decision-style prompts. They are not taken from the live exam.
Use these sample questions as a guided self-assessment for Certified Professional Python Programmer 1 (PCPP1) topics such as object-oriented design, descriptors and properties, decorators, exceptions, generators, context managers, packaging, testing, and maintainable Python structure. The prompts emphasize professional code reasoning rather than syntax recall alone.
The sample set below is part of the Python Institute PCPP1 guide path:
Work through each prompt before opening the explanation. PCPP1 questions often ask whether a design is maintainable, testable, and idiomatic, not just whether it runs once.
Topic: Property validation
A class stores a percentage value that must stay between 0 and 100. Other code should access it as obj.percent, but every assignment must be validated. Which design is most appropriate?
__str__ so invalid values are hidden when printed.Best answer: D
Explanation: A property preserves normal attribute syntax while centralizing validation in the setter. The backing attribute stores the actual value, and the setter enforces the invariant whenever code assigns to the public property.
Why the other choices are weaker:
What this tests: Encapsulation, properties, validation, invariants, and maintainable class design.
Related topics: Properties; Setters; Encapsulation; Validation; Object-oriented design
Topic: Generator behavior
What is printed by this code?
1def numbers():
2 print("start")
3 yield 1
4 print("middle")
5 yield 2
6
7gen = numbers()
8print("created")
9print(next(gen))
10print(next(gen))
start, created, 1, middle, 2created, start, 1, middle, 2created, 1, 2, start, middleStopIteration before printing 2.Best answer: B
Explanation: Calling a generator function creates a generator object but does not execute the function body. The body starts when next(gen) is called. The first next prints start and yields 1; the second resumes after the first yield, prints middle, and yields 2.
Why the other choices are weaker:
What this tests: Lazy generator execution, yield, suspension, and resume order.
Related topics: Generators; yield; Iterators; next; Execution order
Topic: Context manager cleanup
A file-processing class opens a temporary resource and must close it even if processing raises an exception. Which implementation detail is most important?
__init__ because initialization always runs first.except Exception block that silently ignores every failure.__exit__ or use a with-compatible resource so cleanup runs when the block exits.__repr__ so the object displays the file path during debugging.Best answer: C
Explanation: A context manager expresses resource lifetime directly. __enter__ sets up the resource, and __exit__ runs when the with block exits, including when an exception occurs. That makes cleanup reliable and visible in the calling code.
Why the other choices are weaker:
What this tests: Context managers, deterministic cleanup, exception-safe resource handling, and professional Python patterns.
Related topics: Context managers; with; __enter__; __exit__; Resource cleanup
Topic: Decorator metadata
A decorator logs function calls and returns an inner wrapper. After applying it to several functions, documentation tools show every decorated function with the wrapper’s name and docstring. What should the decorator use?
functools.wraps on the wrapper function to preserve metadata from the wrapped function.str() on the wrapped function before calling it.Best answer: A
Explanation: functools.wraps copies useful metadata such as __name__, __doc__, and annotations from the original function to the wrapper. That keeps debugging, introspection, and documentation output aligned with the decorated function.
Why the other choices are weaker:
What this tests: Decorator implementation, introspection metadata, and maintainability.
Related topics: Decorators; functools.wraps; Metadata; Introspection; Documentation
Tech Exam Lexicon and IT Mastery are independent study tools. They are not affiliated with, endorsed by, or sponsored by Python Institute or any certification body.