Python Institute PCPP1 - Certified Professional in Python Programming 1 PCPP-32-101 Exam Questions

Page: 1 / 14
Total 45 questions
Question 1

Select the true statements about the sqlite3 module. (Select two answers.)



Answer : C, D

1. The execute method is provided by the Cursor class

This statement is true because the execute method is one of the methods of the Cursor class in the sqlite3 module. The Cursor class represents an object that can execute SQL statements and fetch results from a database connection. The execute method takes an SQL query as an argument and executes it against the database. For example, cur = conn.cursor (); cur.execute (''SELECT * FROM table'') creates and executes a cursor object that selects all rows from a table.

2. The fetchone method returns None when no rows are available

This statement is true because the fetchone method is another method of the Cursor class in the sqlite3 module. The fetchone method fetches the next row of a query result set and returns it as a single tuple or None if no more rows are available. For example, row = cur.fetchone () fetches and returns one row from the cursor object or None if there are no more rows.


Question 2

Select the true statement related to PEP 257.



Answer : B

The true statement related to PEP 257 isOption B. According to PEP 257, string literals occurring elsewhere in Python code may also act as documentation. They are not recognized by the Python bytecode compiler and are not accessible as runtime object attributes (i.e. not assigned todoc), but two types of extra docstrings may be extracted by software tools: String literals occurring immediately after a simple assignment at the top level of a module, class, orinitmethod are called ''attribute docstrings''.String literals occurring immediately after another docstring are called ''additional docstrings''1.


Question 3

What is a___traceback___?

(Select two answers )



Answer : A, D

The correct answers areA. An attribute owned by every exception objectandD. An attribute that holds interesting information that is particularly useful when the programmer wants to store exception details in other objects. A traceback is an attribute of an exception object that contains a stack trace representing the call stack at the point where the exception was raised. The traceback attribute holds information about the sequence of function calls that led to the exception, which can be useful for debugging and error reporting.


Question 4

Which of the following examples using line breaks and different indentation methods are compliant with PEP 8 recommendations? (Select two answers.)

A)

B)

C)



Answer : B, D

The correct answers areB. Option BandD. Option D. Both options B and D are compliant with PEP 8 recommendations for line breaks and indentation. PEP 8 recommends using 4 spaces per indentation level and breaking lines before binary operators. In option B, the arguments to theprintfunction are aligned with the opening delimiter, which is another acceptable way to format long lines according to PEP 8. In option D, the second line is indented by 4 spaces to distinguish it from the next logical line.


Question 5

What is ElementTree?



Answer : D

ElementTree is a Python built-in module that provides a simple and efficient API for parsing and creating XML data. It allows you to access and manipulate XML data in a very straightforward way, making it easy to write XML processing applications.


This statement is true because ElementTree is a module in the standard library of Python that provides an API for working with XML data. The module supports parsing XML from strings or files, creating XML trees from scratch or modifying existing ones, searching and iterating over XML elements, and writing XML data to strings or files.

Question 6

What does the term deserialization mean? Select the best answer.



Answer : A

Deserialization is the process of converting data that has been serialized

For example, if you have a Python objectmy_objand you want to serialize it to a JSON string, you might do something like this:

import json

serialized_obj = json.dumps(my_obj)

To deserialize the JSON string back into a Python object, you would use thejson.loads()method:

deserialized_obj = json.loads(serialized_obj)

This would convert the JSON string back into its original Python object form.


Official Python Documentation on Serialization:https://docs.python.org/3/library/pickle.html#module-pickle

Real Python Tutorial on Serialization and Deserialization in Python:https://realpython.com/python-serialization/

Deserialization is the process of converting a sequence of bytes, such as a file or a network message, into a Python object. This is the opposite of serialization, which is the process of converting a Python object into a sequence of bytes for storage or transmission.

Question 7

Look at the following examples of comments and docstrings in Python Select the ones that are useful and compliant with PEP 8 recommendations (Select the two best answers.)

A)

B)

C)

D)



Answer : B, D

According to PEP 8 recommendations, the two best options areOption BandOption D.

Option B follows PEP 8's suggestion that all lines should be limited to 79 characters and for longer blocks of text like docstrings or comments, the length should be limited to 72 characters1. Option D follows PEP 8's conventions for writing good documentation strings (a.k.a. ''docstrings'') which are immortalized in PEP 257.It suggests writing docstrings for all public modules, functions, classes, and methods2.


Page:    1 / 14   
Total 45 questions