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

Page: 1 / 14
Total 45 questions
Question 1

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 2

Which sentence about the property decorator is false?



Answer : A

The@propertydecorator should be defined after the method that is responsible for setting an encapsulated attribute is a false sentence. In fact, the@propertydecorator should be defined before the method that is used to set the attribute value. The@propertydecorator and the setter and deleter methods work together to create an encapsulated attribute, which is used to provide control over the attribute's value.


Official Python documentation on Property:https://docs.python.org/3/library/functions.html#property

The@propertydecorator is used to designate a method as a getter for an instance attribute. The method decorated with@propertyshould be defined before any setter or deleter methods for the same attribute.

Question 3

Analyze the following snippet and choose the best statement that describes it.



Answer : C

The correct answer isC. Excalibur is the value passed to an instance variable. In the given code snippet,self.nameis an instance variable of theSwordclass. When an instance of theSwordclass is created withvarl = Sword('Excalibur'), the value'Excalibur'is passed as an argument to the__init__method and assigned to thenameinstance variable of thevarlobject.

The code defines a class calledSwordwith an__init__method that takes one parametername. When a new instance of theSwordclass is created withvarl = Sword('Excalibur'), the value of the'Excalibur'string is passed as an argument to the__init__method, and assigned to theself.nameinstance variable of thevarlobject.


Official Python documentation on Classes:https://docs.python.org/3/tutorial/classes.html

Question 4

Select the true statement about the socket. gaierror exception.



Answer : D

The socket.gaierror exception is raised when an address-related error caused by the getaddrinfo() and getnameinfo() functions occurs. These functions are used to translate hostnames to IP addresses and vice versa, and the gaierror exception is raised if they fail to perform this translation.


Official Python documentation on socket.gaierror:https://docs.python.org/3/library/socket.html#socket.gaierror

Question 5

Which of the following methods allow you to load a configuration using ConfigParser? (Select two answers.)



Answer : A, D

ConfigParser is a built-in library in Python that allows you to read and write configuration files. The read method is used to read the configuration file which can be in any of the supported file formats, such as INI, YAML, and JSON. The read_dict method is used to read the configuration from a Python dictionary. The read_conf and read_str options are not valid methods in the ConfigParser module.

Therefore, the correct options to load a configuration using ConfigParser are A. read and D. read_string.


Question 6

Select the true statement about the___name___attribute.



Answer : D

The true statement about the__name__attribute isD.nameis a special attribute, which is inherent for classes, and it contains the name of a class. The__name__attribute is a special attribute of classes that contains the name of the class as a string.

The__name__attribute is a special attribute in Python that is available for all classes, and it contains the name of the class as a string. The__name__attribute can be accessed from both the class and its instances using the dot notation.


Official Python documentation on Classes:https://docs.python.org/3/tutorial/classes.html#class-objects

Question 7

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.


Page:    1 / 14   
Total 45 questions