Browse Python Institute Certification Guides

Python Institute PCPP2 Sample Questions with Explanations

Python Institute PCPP2 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 2 (PCPP2) topics such as advanced Python design, concurrency choices, serialization, networking boundaries, performance, testing, packaging, and production-quality maintainability. The prompts focus on architecture and operational trade-offs in Python systems.

Where these questions fit in the PCPP2 guide

The sample set below is part of the Python Institute PCPP2 guide path:

PCPP2 advanced Python sample questions

Work through each prompt before opening the explanation. PCPP2 questions tend to reward system-level reasoning: safe concurrency, clear interfaces, testable boundaries, and performance choices backed by measurement.


Question 1

Topic: Choosing concurrency for I/O

A Python service must call 100 independent HTTP APIs and combine their responses. Each call spends most of its time waiting on network I/O. CPU use is low. Which design is usually the best starting point?

  • A. Use asynchronous I/O or a bounded pool of concurrent workers so the service can overlap waiting time without starting unlimited work.
  • B. Run the calls one at a time because concurrency is useful only for CPU-bound programs.
  • C. Start one unbounded thread per URL and ignore timeouts because the operating system will manage everything.
  • D. Rewrite the whole service in C before measuring the Python bottleneck.

Best answer: A

Explanation: Network calls are I/O-bound, so overlapping waits can improve throughput. The important professional detail is bounding concurrency and handling timeouts or failures, not simply creating unlimited work.

Why the other choices are weaker:

  • B misses the main benefit of concurrency for I/O-bound work.
  • C risks resource exhaustion and weak failure control.
  • D jumps to a rewrite before identifying a CPU bottleneck.

What this tests: I/O-bound concurrency, bounded work, async or worker-pool design, and practical performance reasoning.

Related topics: Async I/O; Threads; Worker pools; HTTP clients; Timeouts


Question 2

Topic: Safe serialization format

A service receives user-submitted data over an API. The data contains simple nested structures: strings, numbers, lists, and dictionaries. The service must parse the payload safely. Which format and approach is strongest?

  • A. Accept Python pickle from clients because it preserves arbitrary Python objects.
  • B. Use eval() on the request body because the payload resembles Python literals.
  • C. Use a data format such as JSON and validate the decoded structure against the expected schema.
  • D. Accept any bytes and let downstream code discover whether the object is usable.

Best answer: C

Explanation: JSON is appropriate for simple cross-system data structures, and schema validation checks that the decoded data matches what the service expects. Arbitrary object deserialization or code evaluation is unsafe for user-submitted payloads.

Why the other choices are weaker:

  • A is unsafe for untrusted input because pickle can construct arbitrary Python objects.
  • B executes input as code and is not an API parsing strategy.
  • D delays validation and lets bad data move deeper into the system.

What this tests: Serialization boundaries, untrusted input, schema validation, and secure API design.

Related topics: JSON; Serialization; Validation; Security; API payloads


Question 3

Topic: Testing external dependencies

A function sends a request to a payment provider. Unit tests should verify retry and error-handling behavior without making real network calls or charging accounts. What is the strongest testing approach?

  • A. Run tests only in production because that is where the real payment provider exists.
  • B. Replace the external dependency with a mock, fake, or test double that simulates success, timeout, and provider-error responses.
  • C. Remove all retry logic so the function is easier to test.
  • D. Sleep for a random number of seconds in every test to imitate network conditions.

Best answer: B

Explanation: A test double lets unit tests control external behavior and verify how the code reacts to success, timeouts, and errors. Real provider integration can be tested separately with controlled credentials and environment boundaries.

Why the other choices are weaker:

  • A is risky and makes tests slow, expensive, and hard to reproduce.
  • C weakens production behavior to simplify tests.
  • D adds flakiness without deterministic failure scenarios.

What this tests: Test isolation, mocks or fakes, external-service boundaries, and deterministic error handling.

Related topics: Unit testing; Mocking; Test doubles; External APIs; Retry logic


Question 4

Topic: Performance investigation

A Python data-processing job became slower after a refactor. The team suspects a nested loop is expensive, but they are not sure. What should they do first?

  • A. Add more comments around the nested loop because comments improve runtime behavior.
  • B. Replace every list with a tuple because tuples are always faster in every workload.
  • C. Rewrite the entire job in another language before measuring.
  • D. Profile the job with representative input, identify the actual hot path, and then optimize the code or algorithm that dominates runtime.

Best answer: D

Explanation: Professional performance work starts with measurement. Profiling representative input identifies where time is actually spent. The right optimization may be an algorithm change, a data-structure change, batching, caching, or a targeted implementation improvement.

Why the other choices are weaker:

  • A improves maintainability but not runtime speed.
  • B is an overgeneralized micro-optimization.
  • C is premature and may not address the real bottleneck.

What this tests: Profiling discipline, representative workloads, algorithmic thinking, and avoiding premature optimization.

Related topics: Profiling; Performance; Algorithms; Refactoring; Optimization

Independent study note

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.

Revised on Sunday, May 10, 2026