Home / PCPP1: Certified Professional in Python Programming 1 (PCPP-32-101) / Mock exam
PCPP1: Certified Professional in Python Programming 1 (PCPP-32-101) Exam-style mock test

PCPP1 Certified Professional in Python Programming 1 Practice Exams|Practice test

Full explanations Exam format Pass line 70%
33 USD One-time · lifetime access
Enroll →

Sample questions

Example1 · Advanced Object-Oriented Programming
A data tooling team defines a class Pipeline with a class variable runs = 0. In __init__ they write self.runs += 1 for every new object. After creating three Pipeline objects, what does Pipeline.runs evaluate to?
・3, because the shared class variable is bumped once per object
Incorrect. self.runs += 1 reads the class value but the assignment creates a new instance attribute, so the class variable is never updated.
✓0
Correct. self.runs += 1 binds a per-object instance attribute and leaves the class variable Pipeline.runs untouched at 0.
・1
Incorrect. Each object shadows the class variable with its own instance attribute equal to 1, but the class variable itself stays 0.
・The access raises AttributeError at the class level
Incorrect. Pipeline.runs is a valid class attribute, so reading it returns an integer rather than raising.
Explanation
Augmented assignment on self reads the class variable but writes an instance attribute, so the class variable is not mutated.
Example2 · Coding Conventions, Best Practices, and Standardization (PEP)
A data tooling team runs flake8 in CI, and a new ETL module keeps failing the E501 check. Which PEP 8 rule is the module most likely violating?
✓Limiting each line to a maximum of 79 characters in length
Correct. E501 is the line-too-long warning, and PEP 8 recommends limiting lines to 79 characters.
・Using literal tab characters rather than spaces for every one of the indentation levels in the file
Incorrect. Tab-versus-space issues are flagged by W191 or E101, not by the E501 line-length check.
・Placing two blank lines between consecutive top-level function and class definitions in the module
Incorrect. Blank-line spacing between definitions is enforced by E301 through E306, not E501.
・Importing all of the standard library modules before any of the third-party modules are imported
Incorrect. Import ordering is a convention but is not what the E501 line-length check reports.
Explanation
The E501 code specifically reports lines exceeding the recommended maximum length, which PEP 8 sets at 79 characters for code.
Example3 · GUI Programming with tkinter
A data tooling engineer builds a small dashboard with tkinter. They instantiate the root window with tkinter.Tk() and add several widgets, but the window flashes and closes immediately when the script ends. Which call must be added so the application keeps displaying and responding to events?
・root.start()
Incorrect. Tk root objects have no start() method, so this raises an AttributeError.
✓root.mainloop()
Correct. mainloop() enters tkinter's event loop, keeping the window alive and dispatching events until it is closed.
・Call the module-level function tkinter.run_event_loop(root) once near the bottom
Incorrect. tkinter exposes no module-level run_event_loop function; the loop is started through the root widget's mainloop method instead.
・root.wait()
Incorrect. wait() is not the method that runs the event loop; without mainloop the program ends and the window disappears.
Explanation
A tkinter GUI stays responsive only while the event loop runs, which is started by calling mainloop() on the root window.
Example4 · Network Programming and Working with REST APIs
A fintech backend exposes a REST endpoint /accounts/{id}/balance. A client needs to retrieve the current balance without changing any server state. Which HTTP method should the client use for this safe, idempotent read?
✓GET
Correct. GET is the safe, idempotent method used to retrieve a representation of a resource such as the current balance.
・POST
Incorrect. POST is typically non-idempotent and is used to create resources or trigger processing, not for a plain read.
・PATCH
Incorrect. PATCH applies a partial modification to a resource, so it changes server state rather than reading it.
・DELETE
Incorrect. DELETE removes the target resource and is clearly not a read operation.
Explanation
REST maps CRUD reads to GET, which is defined as safe and idempotent and must not alter resource state.
Example5 · File Processing and Communicating with the Program Environment
A fintech batch tool is launched as 'python settle.py 2024-01 EUR'. Inside the script you need the trailing arguments only, as the list ['2024-01', 'EUR'], regardless of how the interpreter was invoked. Which expression gives you exactly that?
✓sys.argv[1:]
Correct. sys.argv[0] is the script name, so slicing from index 1 yields ['2024-01', 'EUR'].
・sys.argv[0]
Incorrect. Index 0 holds the script name 'settle.py', not the arguments.
・sys.argv[2]
Incorrect. Index 2 is a single element ('EUR'), not the full list of trailing arguments.
・sys.argv, but only after you first manually strip the interpreter path and the script name yourself
Incorrect. sys.argv already excludes the interpreter path; no manual stripping is needed, so this is wrong.
Explanation
sys.argv[0] is always the script name, and the passed arguments begin at index 1, so sys.argv[1:] is the trailing list.
Example6 · Advanced Object-Oriented Programming
In a fintech backend, the Account class declares a class attribute interest_rate = 0.02. During a batch job, a developer runs acc = Account(); acc.interest_rate = 0.05 for one specific account object. After this assignment, what is the effect on other Account instances and the class attribute?
✓Only acc gains an instance attribute shadowing the class attribute; Account.interest_rate and other instances still see 0.02
Correct. Assigning through the instance creates a new instance attribute that shadows the class attribute only for acc; the class and other instances are unaffected.
・Account.interest_rate itself is rebound to 0.05, so every existing and future instance now reports 0.05
Incorrect. Instance assignment never rebinds the class attribute; only Account.interest_rate = 0.05 would do that.
・A TypeError is raised because class attributes declared at class scope cannot be overridden on an instance
Incorrect. There is no such restriction; instance assignment is always permitted and simply shadows the class value.
・Python propagates the new value to all instances that were created before the assignment but not to those created afterward
Incorrect. No such selective propagation exists; shadowing affects only the single instance assigned to.
Explanation
Writing to an attribute via an instance always binds it on the instance, shadowing the class attribute, which remains intact for the class and all other instances.
Example7 · Advanced Object-Oriented Programming
A devops engineer models a deployment pipeline with a class whose retry count must never be set below zero. They want attribute-style access (pipeline.retries = 5) while rejecting negatives. Which approach fits best?
・Expose the raw attribute and hope callers never assign negatives
Incorrect. Leaving the attribute raw provides no validation at all and freely permits negative assignments to it.
✓Wrap retries with @property plus a setter that validates the value
Correct. A @property getter with a validating setter gives attribute-style access while rejecting negatives.
・Make retries a module-level global guarded by a shared lock object
Incorrect. A module-level global breaks encapsulation and is entirely unrelated to per-instance validation here.
・Override __getattribute__ to intercept every single attribute lookup on the whole instance
Incorrect. Overriding __getattribute__ for one field is heavy-handed and risks subtle recursion bugs in lookups.
Explanation
property() is the idiomatic way to keep attribute syntax while running validation logic in the setter.
Example8 · Advanced Object-Oriented Programming
On the devops team's Job class, the attribute queue = [] is defined in the class body. Two Job instances are created and each appends an id to self.queue. What happens?
・Each instance gets its own separate list automatically
Incorrect. A class-body list is shared, not copied per instance.
✓Both instances share and mutate the same single list object
Correct. queue is a class variable, so both instances reference and mutate the same list object.
・Appending raises AttributeError because class lists are read-only
Incorrect. Class-level lists are mutable and appending does not raise AttributeError.
・The second append silently replaces the value from the first
Incorrect. Both appends persist because they target one shared list.
Explanation
A mutable default defined in the class body is shared by all instances unless reassigned in __init__.
Example9 · Advanced Object-Oriented Programming
The team wants an alternate constructor on Deployment that builds an instance from a YAML string and must also work correctly for subclasses. Which decorator should the method use?
・@staticmethod, so the subclass type is passed in explicitly
Incorrect. A staticmethod receives no cls, so it cannot honor the calling subclass automatically.
✓@classmethod, because cls lets the correct subclass be instantiated
Correct. A classmethod receives cls, so calling it on a subclass constructs that subclass.
・@property, so the parsed result is cached as an attribute
Incorrect. @property defines computed attribute access, not an alternate constructor.
・No decorator, relying on the implicit self for construction only
Incorrect. A plain method needs an existing instance and cannot act as a constructor.
Explanation
Alternate constructors use @classmethod so cls resolves to the actual (sub)class being called.
Example10 · Advanced Object-Oriented Programming
On the desktop app team, a Widget class defines `count = 0` at the class level. In `__init__`, a developer writes `self.count += 1` for each new widget. After creating three Button instances, what is the value of `Button.count` (accessed on the class)?
✓0, because each instance shadowed the class variable on first assignment
Correct. `self.count += 1` reads the class value then binds a new instance attribute, leaving the class variable at 0.
・3, because the augmented assignment updated the shared class variable each time
Incorrect. Augmented assignment through self creates an instance attribute rather than mutating the shared class variable.
・1, because supposedly only the first instance ever touched the shared class attribute
Incorrect. Every instance creates its own shadowing attribute, so the class value stays 0 regardless of the order.
・An AttributeError is raised, since the count name was apparently never bound on the class at all
Incorrect. count is bound on the class, so no AttributeError occurs at all when the value is later read.
Explanation
`self.count += 1` is `self.count = self.count + 1`; the read uses the class variable but the assignment binds an instance attribute, so the class variable remains 0.
Example11 · Advanced Object-Oriented Programming
A teammate adds a factory to the desktop app's Panel class that should build an instance from a config dict and still work correctly when called on a Sidebar subclass. Which decorator and first parameter should the method use?
・`@staticmethod` with no implicit first parameter so it stays independent
Incorrect. A static method receives no cls, so it cannot build the correct subclass automatically.
・`@property` with self so it can be read like an attribute
Incorrect. A property turns the method into an attribute getter, not a factory.
✓`@classmethod` with cls as the first parameter
Correct. A class method receives cls, so calling it on Sidebar builds a Sidebar instance.
・no decorator with self so the running instance is always available for binding
Incorrect. An instance method needs an existing object and does not receive the class.
Explanation
A class method takes cls, letting factories construct the correct (possibly subclass) type polymorphically.
Example12 · Advanced Object-Oriented Programming
On a web services team, a developer defines a RequestHandler class with a class variable count = 0. Inside __init__, each new handler runs self.count += 1. After creating three handlers, RequestHandler.count is still 0. Why does the class variable remain unchanged?
✓The augmented assignment on self binds a new instance attribute, leaving the class variable untouched
Correct. self.count += 1 reads the class value but assigns the result to a new instance attribute that shadows the class variable.
・Class variables cannot be modified at all after the class body finishes executing
Incorrect. Class variables can be modified via the class object, such as RequestHandler.count += 1.
・The += operator is not supported for integer class variables in Python
Incorrect. The += operator works fine on integers; the issue is where the result is bound.
・Each instance shares one copy of the variable, so the value was overwritten back to 0
Incorrect. The sharing idea is backwards; assignment through self creates a per-instance attribute rather than updating the shared one.
Explanation
Augmented assignment through self rebinds the name as an instance attribute, so the shared class variable stays at its original value.
Example13 · Advanced Object-Oriented Programming
A teammate debugging an API client writes client = ApiClient() then sets client.token = 'abc'. The class defines base_url = 'https://api' as a class variable. What does client.__dict__ contain?
✓{'token': 'abc'}
Correct. Only attributes assigned on the instance appear in its __dict__, so just token is present.
・{'base_url': 'https://api', 'token': 'abc'}
Incorrect. base_url lives in the class __dict__, not the instance dict.
・Both the token and the base_url keys, because instance dicts always copy every class attribute on creation
Incorrect. Instance dicts do not copy class attributes; they stay in the class namespace.
・{'base_url': 'https://api'}
Incorrect. This shows only the class variable, which is not stored on the instance.
Explanation
An instance __dict__ holds only attributes explicitly set on that instance; class variables remain in the class __dict__.
Example14 · Advanced Object-Oriented Programming
A QA automation team writes a TestRunner class with a class attribute 'suites = []' meant to hold shared registered suites. In one test they do runner_a.suites.append('smoke') on an instance, then check TestRunner.suites. What do they observe and why?
✓TestRunner.suites contains 'smoke', because append mutates the single shared list.
Correct. append mutates the shared list object; the instance lookup falls through to the same class attribute, so TestRunner.suites shows 'smoke'.
・TestRunner.suites stays empty, because the instance quietly received a fresh independent copy of the list.
Incorrect. Appending does not create a per-instance copy; only an assignment statement would shadow the class attribute.
・An AttributeError is raised on the append call since instances cannot reach the attribute.
Incorrect. The append is a valid mutation of an existing list, so no AttributeError occurs.
・TestRunner.suites contains 'smoke' only after you also assign it back explicitly to the class later.
Incorrect. No separate assignment is needed because both names already point at the same list object.
Explanation
A mutable class attribute is shared across all instances; in-place mutation via an instance affects the class-level object.
Example15 · Advanced Object-Oriented Programming
The team wants a factory that builds a Report from a raw dict and works correctly for subclasses like HtmlReport. Which decorator should the factory method use so that calling HtmlReport.from_dict(data) returns an HtmlReport?
・Use the @staticmethod decorator on the factory function.
Incorrect. A static method gets no class reference, so it cannot know which subclass called it.
✓Use the @classmethod decorator on the factory function.
Correct. @classmethod receives the actual calling class as cls, so cls(...) builds the right subclass instance.
・Use the @property decorator on the factory function.
Incorrect. @property defines a read accessor, not a factory constructor.
・Use no decorator since a plain instance method already selects the subclass.
Incorrect. An instance method requires an existing object and does not receive the class for a factory.
Explanation
Class methods receive cls, making them the idiomatic way to write polymorphic alternative constructors.
▶ Try 10 free questions (graded)
Measure your readiness with a full mock exam
All questions · full explanations · lifetime access
Enroll(33 USD)