









































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The PrepIQ PCAP 31 03 Certified Associate in Python Programming Ultimate Exam is a comprehensive preparation resource for Python learners. This ultimate exam covers syntax, data structures, functions, modules, and object-oriented programming. Learners gain practical coding skills and problem-solving abilities. Ideal for aspiring developers, this resource supports certification and Python proficiency.
Typology: Exams
1 / 81
This page cannot be seen from the preview
Don't miss anything!










































































Question 1. Which special method is called to create a new instance before init is executed? A) new B) init C) call D) repr Answer: A Explanation: new is a static method that actually creates the object; init then initializes it. Question 2. In Python, which dunder method enables the use of the + operator for custom objects? A) add B) sum C) plus D) concat Answer: A Explanation: Defining add(self, other) allows instances to be added with the
B) __double_leading_underscore C) double_trailing_underscore D) no underscore Answer: B Explanation: Attributes with two leading underscores are mangled to _ClassName__attr to avoid accidental overrides. Question 5. What is the method resolution order (MRO) used for in multiple inheritance? A) Determining the order of attribute deletion B) Deciding which base class’s method is called first C) Sorting class names alphabetically D) Managing garbage collection Answer: B Explanation: MRO defines the linearized order Python follows to resolve attribute and method lookups in a hierarchy. Question 6. Which function returns the MRO of a class as a tuple? A) class.mro() B) class.mro C) inspect.mro(class) D) type.mro(class) Answer: B Explanation: The mro attribute holds the tuple of classes that Python will search for attributes. Question 7. In the abc module, which decorator marks a method as abstract? A) @abstractmethod B) @abstractproperty C) @abstractclassmethod
Question 11. The expression (a is b) tests for what? A) Equality of values B) Identity of objects C) Membership in a collection D) Presence of attribute a in b Answer: B Explanation: The is operator checks whether two variables reference the same object in memory. Question 12. Which module provides functions for shallow and deep copying? A) copy B) shutil C) pickle D) json Answer: A Explanation: copy.copy produces a shallow copy; copy.deepcopy produces a deep copy. Question 13. When defining a custom exception hierarchy, which built-in class should be the ultimate base? A) Exception B) BaseException C) RuntimeError D) SystemExit Answer: B Explanation: All built-in exceptions inherit from BaseException; user-defined exceptions should normally inherit from Exception (a subclass of BaseException) to be catchable by except Exception.
Question 14. In a chained exception, which attribute holds the original exception that caused the current one? A) cause B) context C) traceback D) original Answer: A Explanation: Using raise NewError from OriginalError sets cause to OriginalError, enabling explicit chaining. Question 15. Which attribute of an exception object contains the traceback object? A) traceback B) stack C) info D) tb Answer: A Explanation: traceback stores the traceback chain that can be inspected with traceback module functions. Question 16. Which PEP introduced the style guide that defines indentation, naming, and whitespace rules? A) PEP 8 B) PEP 20 C) PEP 257 D) PEP 484 Answer: A Explanation: PEP 8 is the official Python style guide. Question 17. According to PEP 20, which principle states “Simple is better than complex”?
Answer: A Explanation: PyLint analyzes code for style and logical errors, including PEP 8 compliance. Question 21. In tkinter, which method starts the event loop? A) mainloop() B) run() C) start() D) loop() Answer: A Explanation: root.mainloop() enters the Tkinter event processing loop. Question 22. Which geometry manager places widgets in a grid of rows and columns? A) pack() B) grid() C) place() D) flow() Answer: B Explanation: grid() organizes widgets in a tabular layout. Question 23. Which widget is best suited for displaying an image that can be drawn upon? A) Label B) Canvas C) Button D) Entry Answer: B Explanation: Canvas provides drawing primitives and can display images.
Question 24. Which method binds a left-mouse click event to a callback function on a widget? A) bind("", callback) B) on("", callback) C) connect("", callback) D) listen("click", callback) Answer: A Explanation: bind() registers a handler for the given Tkinter event pattern. Question 25. Which tkinter variable class should be used to track integer values? A) StringVar B) IntVar C) DoubleVar D) BooleanVar Answer: B Explanation: IntVar holds integer values and updates associated widgets automatically. Question 26. In socket programming, which method puts a server socket into listening mode? A) listen() B) bind() C) accept() D) connect() Answer: A Explanation: listen(backlog) tells the OS to accept incoming connection requests. Question 27. Which socket method is used by a client to initiate a connection to a server? A) bind()
Answer: A Explanation: json.dumps serializes a Python object to a JSON formatted string. Question 31. When parsing XML with ElementTree, which method retrieves the text content of an element? A) .text B) .value C) .content D) .data Answer: A Explanation: Element.text holds the textual data inside an XML element. Question 32. In the requests library, which argument is used to send JSON data in a POST request? A) data= B) json= C) payload= D) body= Answer: B Explanation: requests.post(url, json=obj) automatically serializes obj to JSON and sets the appropriate header. Question 33. Which HTTP status code indicates that the request was successful and a new resource was created? A) 200 B) 201 C) 202 D) 204 Answer: B Explanation: 201 Created signals that the server has fulfilled the request and created a new resource.
Question 34. In SQLite, which method finalizes a transaction and makes changes permanent? A) commit() B) save() C) apply() D) flush() Answer: A Explanation: Connection.commit writes all pending changes to the database file. Question 35. Which SQLite cursor method returns an iterator over query results without loading them all into memory? A) fetchall() B) fetchone() C) fetchmany() D) execute() returns an iterator when using .fetchall()? Answer: C Explanation: fetchmany(size) yields rows in batches, reducing memory consumption. Question 36. When writing CSV files with the csv module, which dialect should be used for Excel-compatible files? A) unix B) excel C) excel_tab D) default Answer: B Explanation: csv.excel is the default dialect that matches Excel’s CSV format. Question 37. Which method of ConfigParser reads configuration from a string rather than a file?
Answer: B Explanation: datetime.utcnow() returns the current time in UTC without applying local timezone conversion. Question 41. Which io class provides a in-memory binary stream? A) StringIO B) BytesIO C) TextIOWrapper D) BufferedReader Answer: B Explanation: BytesIO implements a file-like object for binary data held in memory. Question 42. Which protocol does the pickle module use to serialize objects? A) JSON B) XML C) Binary protocol (specific to pickle) D) CSV Answer: C Explanation: pickle serializes Python objects using its own binary protocol versions (0–5). Question 43. What is the primary difference between pickle.dump() and pickle.dumps()? A) dump writes to a file object; dumps returns a bytes object B) dump is for text, dumps is for binary C) dump encrypts data, dumps does not D) dump works only on dictionaries, dumps works on any object Answer: A Explanation: dump(obj, file) writes serialized data to a file-like object; dumps(obj) returns the serialized bytes.
Question 44. Which module provides a persistent, dictionary-like object storage using pickle internally? A) shelve B) dbm C) sqlite D) json Answer: A Explanation: shelve creates a persistent mapping where values are pickled automatically. Question 45. Which built-in function can be used to check if an object is an instance of a given class or its subclass? A) isinstance() B) issubclass() C) type() D) hasattr() Answer: A Explanation: isinstance(obj, cls) returns True if obj’s type is cls or a subclass thereof. Question 46. Which decorator from functools can turn a function into a cached version that stores results? A) @lru_cache B) @memoize C) @cached D) @cacheable Answer: A Explanation: functools.lru_cache caches function calls based on arguments.
B) A proxy object that delegates attribute lookup to the next class in the MRO C) The name of the superclass as a string D) The instance’s dict Answer: B Explanation: super() provides a temporary object that searches for attributes in the MRO after the current class. **Question 51. Which of the following statements about shallow copy is correct? ** A) All nested objects are duplicated. B) Only the top-level container is copied; nested objects are shared. C) It creates a completely independent clone. D) It is performed by the copy.deepcopy function. Answer: B Explanation: Shallow copy copies the container but references the same inner objects. Question 52. In a try/except block, which clause is executed when an exception is raised but not caught by any preceding except clauses? A) else B) finally C) except: D) except BaseException: Answer: D Explanation: A bare except or except BaseException catches any exception not matched earlier. Question 53. Which attribute of an exception object contains the message passed when it was raised? A) args[0] B) message
C) msg D) text Answer: A Explanation: Exception.args is a tuple of arguments; the first element is the message string. Question 54. Which PEP introduced type hinting to Python? A) PEP 8 B) PEP 20 C) PEP 257 D) PEP 484 Answer: D Explanation: PEP 484 defines the typing module and syntax for optional static type hints. Question 55. Which of the following is a correct type hint for a function that returns a list of strings? A) -> List[str] B) -> list(str) C) -> List of str D) -> [str] Answer: A Explanation: Using typing.List, the annotation is -> List[str]. Question 56. In Pylint, which message code indicates a missing docstring? A) C B) W C) E D) R Answer: A
Question 60. In the requests library, which attribute of the Response object contains the HTTP status code? A) status B) code C) status_code D) http_status Answer: C Explanation: response.status_code returns the numeric HTTP status. Question 61. Which HTTP header is commonly used to indicate the media type of the request body? A) Accept B) Content-Type C) Authorization D) User-Agent Answer: B Explanation: Content-Type tells the server the MIME type of the payload (e.g., application/json). Question 62. Which method of a socket object shuts down both reading and writing? A) close() B) shutdown(socket.SHUT_RDWR) C) abort() D) disconnect() Answer: B Explanation: shutdown with SHUT_RDWR disables further sends and receives. Question 63. Which function from the json module can parse a JSON string into a Python dictionary? A) loads()
B) load() C) decode() D) parse() Answer: A Explanation: json.loads(s) deserializes a JSON formatted string. Question 64. Which XML parsing method returns an ElementTree object from a file path? A) parse() B) fromstring() C) load() D) read() Answer: A Explanation: ElementTree.parse('file.xml') reads and parses the XML file. Question 65. In SQLite, which command is used to remove a table from the database? A) DROP TABLE table_name; B) DELETE TABLE table_name; C) REMOVE TABLE table_name; D) ERASE TABLE table_name; Answer: A Explanation: DROP TABLE permanently deletes the table schema and data. Question 66. Which method of a csv.DictReader object returns the next row as a dictionary? A) next() B) readrow() C) nextrow() D) fetch()