CPPP 001 Certified Professional Python Programmer Study Guide & Practice Tests, Exams of Technology

This all-in-one study guide is designed for candidates seeking certification in professional Python programming. It covers Python fundamentals, data types, control structures, functions, object-oriented programming, error handling, file operations, and standard libraries. Advanced topics include data manipulation, automation, scripting, and basic software development practices. The guide features hands-on coding examples, exercises, practice tests, and mock exams to reinforce learning and ensure exam readiness.

Typology: Exams

2025/2026

Available from 02/12/2026

shilpi-jain-3
shilpi-jain-3 🇮🇳

2.5

(11)

80K documents

1 / 83

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPPP 001 Certified Professional Python Programmer
Study Guide & Practice Tests
**Question 1.** Which special method is used to define the string representation of an object that is
meant to be unambiguous and, if possible, evalable?
A) __str__
B) __repr__
C) __format__
D) __unicode__
Answer: B
Explanation: __repr__ should return a string that, when passed to eval(), recreates the object (or at least
gives a detailed, unambiguous description).
**Question 2.** In Python, what does the builtin function isinstance(obj, cls) check?
A) Whether obj and cls are the same object
B) Whether obj is an instance of cls or a subclass thereof
C) Whether cls is a subclass of obj’s type
D) Whether obj’s id equals cls’s id
Answer: B
Explanation: isinstance returns True if obj is an instance of cls or any subclass of cls.
**Question 3.** Which of the following statements about the __init__ method is FALSE?
A) It is automatically called after a new instance is created
B) It can return a value to replace the newly created object
C) It can accept arbitrary positional and keyword arguments
D) It is used to initialize instance attributes
Answer: B
Explanation: __init__ must return None; returning a value does not replace the instance.
**Question 4.** When defining a class that should not be instantiated directly but only subclassed,
which module provides the needed tools?
A) collections
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53

Partial preview of the text

Download CPPP 001 Certified Professional Python Programmer Study Guide & Practice Tests and more Exams Technology in PDF only on Docsity!

Study Guide & Practice Tests

Question 1. Which special method is used to define the string representation of an object that is meant to be unambiguous and, if possible, eval‑able? A) str B) repr C) format D) unicode Answer: B Explanation: repr should return a string that, when passed to eval(), recreates the object (or at least gives a detailed, unambiguous description). Question 2. In Python, what does the built‑in function isinstance(obj, cls) check? A) Whether obj and cls are the same object B) Whether obj is an instance of cls or a subclass thereof C) Whether cls is a subclass of obj’s type D) Whether obj’s id equals cls’s id Answer: B Explanation: isinstance returns True if obj is an instance of cls or any subclass of cls. Question 3. Which of the following statements about the init method is FALSE? A) It is automatically called after a new instance is created B) It can return a value to replace the newly created object C) It can accept arbitrary positional and keyword arguments D) It is used to initialize instance attributes Answer: B Explanation: init must return None; returning a value does not replace the instance. Question 4. When defining a class that should not be instantiated directly but only subclassed, which module provides the needed tools? A) collections

Study Guide & Practice Tests

B) abc C) enum D) typing Answer: B Explanation: The abc (Abstract Base Classes) module provides ABC and @abstractmethod to define abstract classes. Question 5. What is the result of the expression: 5 < 3 < 7? A) True B) False C) SyntaxError D) TypeError Answer: A Explanation: Python supports chained comparisons; 5 < 3 is False, but the overall expression evaluates as (5 < 3) and (3 < 7) → False and True → False. Actually correction: 5 < 3 is False, so whole expression is False. Wait the answer should be B. Answer: B Explanation: In a chained comparison, all individual comparisons must be True. Since 5 < 3 is False, the whole expression is False. Question 6. Which magic method enables an object to be used with the len() built‑in function? A) size B) len C) count D) length Answer: B Explanation: len is called by len() to return the length of a container. Question 7. In multiple inheritance, which algorithm determines the order in which base classes are searched for attributes?

Study Guide & Practice Tests

D) Extends‑a Answer: B Explanation: Composition models a “has‑a” relationship where one object contains or uses another. Question 11. What is the purpose of the *args parameter in a function definition? A) To collect excess positional arguments into a tuple B) To collect excess keyword arguments into a dictionary C) To enforce exactly two arguments D) To indicate the function returns multiple values Answer: A Explanation: *args gathers any additional positional arguments into a tuple. Question 12. Which decorator turns a regular method into a class method? A) @staticmethod B) @property C) @classmethod D) @abstractmethod Answer: C Explanation: @classmethod passes the class (cls) as the first argument instead of the instance. Question 13. What is the effect of using the @property decorator on a method? A) The method becomes a static method B) The method can be accessed like an attribute, enabling getter behavior C) The method is hidden from introspection D) The method is automatically cached Answer: B Explanation: @property allows a method to be accessed like an attribute, providing controlled read access.

Study Guide & Practice Tests

Question 14. Which built‑in function returns the unique identifier for an object during its lifetime? A) id() B) hash() C) uuid() D) address() Answer: A Explanation: id() returns the memory address (or equivalent) that uniquely identifies the object while it exists. Question 15. When overriding eq in a class, which other method is recommended to also implement for consistency? A) hash B) lt C) repr D) str Answer: A Explanation: Objects that define eq should also define hash (or set it to None) to maintain the contract used by hash‑based collections. Question 16. Which of the following is NOT a valid way to define a read‑only attribute using property? A) Define only a getter method and decorate with @property B) Define a setter method that raises AttributeError C) Use @property.setter and leave the body empty D) Define setattr to block assignments for that attribute Answer: C Explanation: Declaring a setter without implementation still allows assignment; to make it read‑only, either omit the setter or raise an exception.

Study Guide & Practice Tests

D) """\nThis function does X.\n""" Answer: A Explanation: A one‑line docstring should be a single line within triple quotes, without leading/trailing newlines. Question 21. The Zen of Python states “Explicit is better than implicit.” Which coding practice best follows this principle? A) Using *args to hide arguments B) Relying on duck typing without documentation C) Naming variables with clear, descriptive identifiers D) Overloading operators for unclear behavior Answer: C Explanation: Clear naming makes code behavior explicit. Question 22. In Tkinter, which widget is typically used to display a short, non‑editable piece of text? A) Entry B) Label C) Text D) Button Answer: B Explanation: Label shows static text; Entry is for editable single‑line input. Question 23. Which geometry manager arranges widgets in a grid of rows and columns? A) pack() B) place() C) grid() D) layout() Answer: C Explanation: grid() uses a table‑like layout.

Study Guide & Practice Tests

Question 24. What does the mainloop() method do in a Tkinter application? A) Starts the event‑driven loop that processes user actions B) Executes all pending callbacks immediately C) Closes the application window D) Refreshes the screen at a fixed frame rate Answer: A Explanation: mainloop() runs the Tkinter event loop, waiting for events and dispatching callbacks. Question 25. In Tkinter, which variable class should be used to track the state of a Checkbutton? A) StringVar B) IntVar C) DoubleVar D) BooleanVar Answer: B Explanation: Checkbutton typically stores 0/1 integer values, so IntVar is appropriate. Question 26. Which method is called when a widget receives a left‑mouse button click event bound using widget.bind("", handler)? A) handler(event) B) handler() C) handler(event, widget) D) handler(widget) Answer: A Explanation: The callback receives a Tkinter event object as its first argument. Question 27. Which Tkinter widget provides a drawing surface that supports lines, ovals, and custom shapes? A) Canvas

Study Guide & Practice Tests

Answer: B Explanation: The json= argument automatically serializes the object to JSON and sets the appropriate header. Question 31. Which HTTP status code indicates that the request was successful and resulted in the creation of a new resource? A) 200 OK B) 201 Created C) 202 Accepted D) 204 No Content Answer: B Explanation: 201 is the standard code for a successful creation operation. Question 32. In the context of REST, which HTTP verb is conventionally used to retrieve a resource without side effects? A) POST B) PUT C) GET D) DELETE Answer: C Explanation: GET is safe and idempotent for fetching data. Question 33. Which Python module provides functions to parse and construct XML documents? A) json B) csv C) xml.etree.ElementTree D) configparser Answer: C Explanation: xml.etree.ElementTree is the standard library for XML handling.

Study Guide & Practice Tests

Question 34. What does the json.dumps() function do? A) Serialize a Python object to a JSON-formatted string B) Write JSON data to a file C) Parse a JSON string into a Python object D) Convert a dictionary to a CSV file Answer: A Explanation: dumps returns a JSON string representation of the object. Question 35. Which SQLite isolation level is the default when using the sqlite3 module in Python? A) AUTOCOMMIT B) READ UNCOMMITTED C) DEFERRED D) EXCLUSIVE Answer: C Explanation: The default is DEFERRED, meaning the transaction starts when the first write occurs. Question 36. In the sqlite3 module, which method commits the current transaction? A) execute() B) commit() C) close() D) rollback() Answer: B Explanation: commit() finalizes changes made during the transaction. Question 37. When reading a CSV file with the csv module, which class should be used to parse rows as dictionaries keyed by column headers? A) csv.reader

Study Guide & Practice Tests

Explanation: CRITICAL indicates a fatal error that may cause program termination. Question 41. What is the purpose of the pickle module? A) Serialize Python objects to a binary format for later reconstruction B) Convert Python objects to JSON strings C) Read and write CSV files D) Manage configuration files Answer: A Explanation: pickle provides object serialization (pickling) and deserialization (unpickling). Question 42. Which of the following statements about the shelve module is TRUE? A) It stores data in plain text files B) It provides a dictionary‑like interface that persists data on disk C) It only works with JSON‑compatible objects D) It encrypts stored data automatically Answer: B Explanation: shelve uses pickle internally and offers a persistent dict‑like API. Question 43. In Python, what does the @abstractmethod decorator enforce? A) The method must be static B) Subclasses must override the method, otherwise they cannot be instantiated C) The method is automatically implemented by the metaclass D) The method is hidden from introspection Answer: B Explanation: An abstract method must be overridden; otherwise the subclass remains abstract. Question 44. Which of the following is a correct way to define a static method inside a class? A) def static_method(self): ...

Study Guide & Practice Tests

B) @staticmethod def static_method(): ... C) @classmethod def static_method(cls): ... D) def static_method(cls): ... Answer: B Explanation: @staticmethod decorates a method that receives no implicit first argument. Question 45. What is the output of the following code?

class A: def __add__(self, other): return "A plus " + str(other) print(A() + 5)

A) TypeError B) "A plus 5" C) "A plus " D) "A plus main.A" Answer: B Explanation: add is defined to return a string concatenating "A plus " with the string representation of the operand. Question 46. Which magic method is invoked when an object is called as a function, e.g., obj()? A) call

Study Guide & Practice Tests

Answer: C Explanation: import math.sqrt is invalid syntax; you must import the module or the name. Question 50. According to PEP 8, which of the following is the preferred way to import multiple classes from a single module? A) from module import ClassA, ClassB, ClassC B) import module.ClassA, module.ClassB, module.ClassC C) from module import (ClassA, ClassB, ClassC) D) import module; ClassA = module.ClassA; ClassB = module.ClassB Answer: A Explanation: A single line with comma‑separated names is acceptable and clear. Question 51. In a Tkinter application, which method would you use to temporarily disable a Button widget? A) button.state('disabled') B) button.config(state=DISABLED) C) button.disable() D) button.set('disabled') Answer: B Explanation: The state option controls widget activation; DISABLED disables the button. Question 52. Which of the following statements about the Python GIL (Global Interpreter Lock) is TRUE? A) It allows multiple native threads to execute Python bytecode simultaneously B) It prevents race conditions in CPython by allowing only one thread to execute Python code at a time C) It is present in all Python implementations D) It can be disabled with a command‑line flag Answer: B Explanation: The GIL ensures only one thread runs Python bytecode at once in CPython.

Study Guide & Practice Tests

Question 53. What does the built‑in function vars() return when called without arguments inside a method? A) The global variables dictionary B) The local variables dictionary of the current frame C) The attributes of the current object D) None Answer: B Explanation: vars() without arguments returns locals() of the current scope. Question 54. Which of the following is the correct way to ensure that a function’s default mutable argument is not shared across calls? A) def func(arg=[]): ... B) def func(arg=None): if arg is None: arg = [] C) def func(arg=[]): arg = [] D) def func(*arg): ... Answer: B Explanation: Using None as a sentinel avoids the mutable default pitfall. Question 55. In the context of the requests library, which attribute of a Response object contains the HTTP status code? A) response.status B) response.code C) response.status_code D) response.http_status Answer: C Explanation: status_code holds the numeric HTTP status.

Study Guide & Practice Tests

B) threading.Thread(target=my_func).start() C) threading.Thread(my_func).execute() D) threading.Thread(my_func).begin() Answer: B Explanation: start() begins the thread’s activity; run() would execute in the current thread. Question 60. In a class hierarchy, which method resolution order is used when calling super() in a diamond inheritance pattern? A) Depth‑first left‑to‑right B) Breadth‑first C) C3 linearization D) Random order Answer: C Explanation: C3 linearization resolves the diamond problem consistently. Question 61. Which of the following statements about the del method is FALSE? A) It is called when an object’s reference count reaches zero B) It can be relied upon to release external resources deterministically C) It may not be called if the interpreter exits abruptly D) It can be defined to perform cleanup actions Answer: B Explanation: del is not guaranteed to run at a specific time; using context managers is preferred for deterministic cleanup. Question 62. Which of the following is the correct syntax to define a function that accepts any number of positional arguments and returns their sum? A) def sum_all(args): return sum(args) B) def sum_all(args): return sum(args) C) def sum_all(*args): return sum(args)

Study Guide & Practice Tests

D) def sum_all(*args, **kwargs): return sum(args) Answer: A Explanation: *args captures positional arguments as a tuple. Question 63. In the context of the abc module, what does the metaclass ABCMeta provide? A) Automatic implementation of init B) Registration of virtual subclasses and enforcement of abstract methods C) Thread‑safety for abstract classes D) Serialization support for abstract classes Answer: B Explanation: ABCMeta handles abstract method tracking and allows virtual subclass registration. Question 64. Which of the following is the preferred way to format a string that includes variable values in Python 3.6+? A) "Value is %s" % value B) "Value is {}".format(value) C) f"Value is {value}" D) "Value is " + str(value) Answer: C Explanation: f‑strings are concise and evaluated at runtime. Question 65. Which of the following statements about list comprehensions is TRUE? A) They can only produce lists, not other sequence types B) The expression part cannot contain function calls C) They may include an optional if clause to filter items D) They must be written on a single line Answer: C Explanation: An optional if clause can filter elements during comprehension.