PCPP-32-101 Sample Questions

PCPP-32-101 Sample Questions & Answers

Pulls together advanced object-oriented programming through inheritance, polymorphism and composition, by far the biggest weight, plus building GUIs with tkinter, socket-based network programming, file and database processing, and PEP 8 or PEP 257 style conventions.

Launch the full PCPP-32-101 simulator →

Showing 10 of 20 free samples.

  1. Question 1Intermediate

    File Processing and Communicating with a Program's Environment · File Format Processing

    A developer is using the csv module to write data to a file. They want to ensure that each row is written from a dictionary, where the dictionary keys correspond to the header row. Which combination of csv module components should be used to open the file and write the rows?

    Show answer & explanation

    Correct answer: B

    The csv.DictWriter class is specifically designed to write rows from dictionaries. It requires a fieldnames argument during instantiation to define the header. Its writerow method then takes a dictionary and writes the values corresponding to the fieldnames. It's crucial to open the file with newline='' to prevent extra blank rows from being written on some platforms.

  2. Question 2Intermediate

    GUI Programming · GUI toolkits and layout management

    When designing a GUI with tkinter, what is the fundamental difference between the grid and place geometry managers?

    Show answer & explanation

    Correct answer: C

    The grid manager organizes widgets in a table-like structure of rows and columns. This allows the layout to adapt as the window is resized. In contrast, the place manager positions widgets at specific x/y coordinates (either absolute pixels or relative to the container size), which does not automatically adjust well to window resizing, making it less suitable for most applications.

  3. Question 3Intermediate

    Advanced Object-Oriented Programming · Python core syntax operations

    A developer needs to create a custom class that behaves like a dictionary but logs a message every time a key is accessed. Which magic method must be implemented to intercept key retrieval?

    Show answer & explanation

    Correct answer: C

    The __getitem__ method is used to implement evaluation of self[key], which is how dictionary values are accessed. By implementing this method, the developer can add custom logic (like logging) before retrieving and returning the value. __getattr__ is for attribute access (e.g., self.key), and __get__ is part of the descriptor protocol.

  4. Question 4Intermediate

    Advanced Object-Oriented Programming · (De)serialization of Python objects

    What is the primary motivation for using the shelve module over the pickle module for object persistence?

    Show answer & explanation

    Correct answer: C

    The main advantage of shelve is its dictionary-like interface. It stores pickled objects in a database file, allowing you to access, add, or modify individual objects by their string key without having to load and rewrite the entire data structure. In contrast, pickle typically serializes an entire object graph to a stream, which must be read sequentially.

  5. Question 5Beginner

    Network Programming · Working with sockets in Python

    True or False: In Python's socket module, TCP sockets are created using socket.SOCK_DGRAM and UDP sockets are created using socket.SOCK_STREAM.

    Show answer & explanation

    Correct answer: B

    The statement is false. It has the constants reversed. socket.SOCK_STREAM is used for connection-oriented TCP sockets, while socket.SOCK_DGRAM is used for connectionless UDP sockets.

  6. Question 6Intermediate

    File Processing and Communicating with a Program's Environment · File Format Processing

    An application uses the logging module to record events. The requirement is to have a rotating log file that creates a new file once the current one reaches 1MB, keeping a backup of the last 5 log files. Which handler from the logging.handlers module is most appropriate for this task?

    Show answer & explanation

    Correct answer: C

    The RotatingFileHandler is designed specifically for this purpose. It rotates log files based on their size. You can configure it with a maximum size (maxBytes) and the number of backup files to keep (backupCount). TimedRotatingFileHandler rotates based on time intervals, not size.

  7. Question 7IntermediateSelect 2

    GUI Programming · Using widgets and handling events

    A developer is building a Tkinter application and needs to retrieve the text currently entered in an Entry widget. If the Entry widget is associated with a tk.StringVar named entry_var, which two of the following methods are valid ways to get the widget's current text content? (Select TWO)

    Show answer & explanation

    Correct answers: A, C

  8. Question 8Advanced

    Advanced Object-Oriented Programming · Metaprogramming

    What is the primary role of a metaclass in Python?

    Show answer & explanation

    Correct answer: B

    A metaclass defines the rules for creating classes, just as a class defines the rules for creating instances. It intercepts the class creation process (e.g., in __new__ or __init__) and allows you to modify the class before it is fully formed. This is useful for framework development, ORMs, and enforcing conventions across a family of classes.

  9. Question 9Intermediate

    Advanced Object-Oriented Programming · Shallow and deep copy operations

    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 & explanation

    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.

  10. Question 10Beginner

    File Processing and Communicating with a Program's Environment · File Format Processing

    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 & explanation

    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.

Ready for the real thing?

The full PCPP-32-101 simulator has every exam-style question, timed mode, and instant scoring.