Skip to content

PCPP-32-101 PCPP1 – Certified Professional Python Programmer Level 1 Practice Questions

Prepare for PCPP-32-101 with more than an answer.

218 questions in the full set20 sample questionsUpdated Aug 21, 2026
Exam fee
$295 USD
Level
Professional
Valid for
Lifetime
Domains covered on the exam 5
  1. Advanced Object-Oriented Programming35%
  2. Coding Conventions, Best Practices, and Standardization12%
  3. GUI Programming20%
  4. Network Programming18%
  5. File Processing and Communicating with a Program's Environment15%
  1. 1

    What is the output of the following code snippet involving shallow and deep copying?

    import copy
    
    list_a = [1, 2, [3, 4]]
    list_b = copy.copy(list_a)
    list_c = copy.deepcopy(list_a)
    
    list_a[2][0] = 99
    
    print(list_b[2][0], list_c[2][0])
    
    Show answer details

    Correct answer: B

    copy.copy() performs a shallow copy. It creates a new list list_b, but the elements inside are references to the same objects as in list_a. Therefore, the nested list [3, 4] is shared. When list_a[2][0] is modified, the change is visible in list_b.

    copy.deepcopy() performs a deep copy, recursively copying all objects. list_c gets a completely independent copy of the nested list, so it remains unaffected by the change to list_a.

  2. 2

    A developer needs to parse an application configuration file named app.ini. The file contains sections, keys, and values. Which standard library module is specifically designed for parsing this type of file format?

    Show answer details

    Correct answer: C

    The configparser module is the standard Python library for working with configuration files in the format of INI files. It allows you to read, write, and manipulate structured configuration data organized into sections with key-value pairs.

  3. 3

    In the context of PEP 20, The Zen of Python, what does the aphorism "There should be one-- and preferably only one --obvious way to do it" primarily advocate for?

    Show answer details

    Correct answer: C

    This principle, often attributed to Python's design philosophy, favors clarity and predictability. It suggests that for a given task, the language should make the best approach easy to discover and use, reducing ambiguity and cognitive load for developers reading the code. This enhances readability and maintainability.

  4. 4

    A developer needs to design a system with a Logger class that should only ever have one instance throughout the entire application lifecycle. Subsequent attempts to create a Logger object should return the existing instance. Which OOP design pattern is best suited for this requirement, and how is it typically implemented in Python?

    Show answer details

    Correct answer: B

    The Singleton pattern ensures a class has only one instance and provides a global point of access to it. A common Pythonic implementation involves overriding the __new__ method. This method controls the object creation process. It can check if a class-level attribute holding the instance already exists; if not, it creates it using super().__new__(cls) and stores it, otherwise, it returns the existing instance.

  5. 5

    In a client-server application using raw sockets, the client sends a message, and the server must send back a response. After the server sends its response with socket.sendall(), what is the most reliable way for the server to ensure the client has received the entire message before the server closes the connection?

    Show answer details

    Correct answer: B

    Calling socket.shutdown(socket.SHUT_WR) signals to the client that the server is done sending data (a TCP FIN). The server can then enter a recv() loop. The client's TCP stack will acknowledge the data, and once the client closes its end, the server's recv() will return b'', indicating a graceful shutdown. This confirms the client has processed the FIN and, by extension, the preceding data. Simply calling close() can lead to a TCP RST (reset), potentially causing the client to lose data still in its receive buffer.

  6. 6

    You are creating a custom list-like class by subclassing list. You want to override the append method to only allow integers to be added. Which implementation is correct?

    Show answer details

    Correct answer: A

    This is the correct approach. The class IntList inherits from list. It overrides the append method. Inside the new method, it first performs a type check using isinstance(). If the check fails, it raises an appropriate exception. If it passes, it uses super().append(value) to call the parent class's (list's) original append method to perform the actual append operation.

  7. 7

    Case Study: GUI Application Configuration

    A developer is creating a desktop utility with Tkinter. The application needs a settings window where users can configure various options. One of these options is the application's theme, which can be 'Light', 'Dark', or 'System Default'. The user's choice must be mutually exclusive—only one theme can be active at a time.

    The settings window is implemented as a Toplevel widget. The developer wants to use Radiobutton widgets for the theme selection. To manage the state of these radio buttons, a StringVar is used. When the user clicks the 'Save' button, the application should be able to retrieve the currently selected theme from the StringVar.

    Below is a simplified diagram of the required widget relationships:

    graph TD MainWindow --> SettingsButton SettingsButton -- opens --> SettingsWindow(Toplevel) subgraph SettingsWindow SharedVar(StringVar) RB1(Radiobutton 'Light') RB2(Radiobutton 'Dark') RB3(Radiobutton 'System') SaveButton(Button 'Save') end SharedVar --> RB1 SharedVar --> RB2 SharedVar --> RB3 SaveButton -- reads --> SharedVar

    Which code snippet correctly implements this group of mutually exclusive Radiobutton widgets?

    Show answer details

    Correct answer: A

    This is the correct implementation. A single StringVar (theme_var) is created to hold the state. Each Radiobutton is linked to this same variable via the variable option. The value option for each button specifies the string that will be stored in theme_var when that button is selected. Because they all share the same variable, selecting one automatically deselects the others.

  8. 8

    A financial services company is developing a framework where different asset classes must be represented. A base Asset class is defined. Stock and Bond classes inherit from Asset. A Portfolio class is then created, which holds a collection of Asset objects. Which two primary OOP principles are demonstrated by the Portfolio class's relationship with the Asset, Stock, and Bond classes?

    Show answer details

    Correct answer: B

    The Portfolio class holding a collection of Asset objects is a classic example of Composition (a 'has-a' relationship). Since the collection can contain objects of subclasses like Stock and Bond, and the Portfolio can operate on them through the common Asset interface, this demonstrates Polymorphism. Inheritance is shown by Stock and Bond extending Asset, but the question specifically asks about the Portfolio's relationship.

  9. 9

    A developer needs to create a decorator that accepts an argument, for example, @retry(attempts=3). Which code structure correctly implements a decorator that takes its own arguments?

    Show answer details

    Correct answer: C

    To create a decorator that accepts arguments, you need a factory pattern. This is typically implemented with three levels of nested functions. The outermost function accepts the decorator's arguments (e.g., attempts=3) and returns the actual decorator. The middle function is the decorator itself, which accepts the function to be decorated. The innermost function is the wrapper that contains the new logic and calls the original function.

  10. 10

    You are reviewing Python code and find the following line inside an except block:

    raise ConnectionError("Failed to connect to database") from exc

    What is the primary purpose of the from exc syntax in this context?

    Show answer details

    Correct answer: D

    The raise NewException from OriginalException syntax is used for explicit exception chaining. It sets the __cause__ attribute on the new exception to the original one. This indicates that the new exception was raised in direct response to the original one, and both tracebacks are displayed to aid in debugging.

Create an account to continue.