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.
- Question 1Intermediate
File Processing and Communicating with a Program's Environment · File Format Processing
A developer is using the
csvmodule 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 ofcsvmodule components should be used to open the file and write the rows?Show answer & explanation
Correct answer: B
The
csv.DictWriterclass is specifically designed to write rows from dictionaries. It requires afieldnamesargument during instantiation to define the header. Itswriterowmethod then takes a dictionary and writes the values corresponding to the fieldnames. It's crucial to open the file withnewline=''to prevent extra blank rows from being written on some platforms. - Question 2Intermediate
GUI Programming · GUI toolkits and layout management
When designing a GUI with
tkinter, what is the fundamental difference between thegridandplacegeometry managers?Show answer & explanation
Correct answer: C
The
gridmanager organizes widgets in a table-like structure of rows and columns. This allows the layout to adapt as the window is resized. In contrast, theplacemanager 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. - 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 ofself[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. - Question 4Intermediate
Advanced Object-Oriented Programming · (De)serialization of Python objects
What is the primary motivation for using the
shelvemodule over thepicklemodule for object persistence?Show answer & explanation
Correct answer: C
The main advantage of
shelveis 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,pickletypically serializes an entire object graph to a stream, which must be read sequentially. - Question 5Beginner
Network Programming · Working with sockets in Python
True or False: In Python's
socketmodule, TCP sockets are created usingsocket.SOCK_DGRAMand UDP sockets are created usingsocket.SOCK_STREAM.Show answer & explanation
Correct answer: B
The statement is false. It has the constants reversed.
socket.SOCK_STREAMis used for connection-oriented TCP sockets, whilesocket.SOCK_DGRAMis used for connectionless UDP sockets. - Question 6Intermediate
File Processing and Communicating with a Program's Environment · File Format Processing
An application uses the
loggingmodule 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 thelogging.handlersmodule is most appropriate for this task?Show answer & explanation
Correct answer: C
The
RotatingFileHandleris 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).TimedRotatingFileHandlerrotates based on time intervals, not size. - 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
Entrywidget. If theEntrywidget is associated with atk.StringVarnamedentry_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
- 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. - 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 listlist_b, but the elements inside are references to the same objects as inlist_a. Therefore, the nested list[3, 4]is shared. Whenlist_a[2][0]is modified, the change is visible inlist_b.copy.deepcopy()performs a deep copy, recursively copying all objects.list_cgets a completely independent copy of the nested list, so it remains unaffected by the change tolist_a. - 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
configparsermodule 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.