Free Python Institute PCPP-32-101 Exam Actual Questions

The questions for PCPP-32-101 were last updated On Nov 17, 2024

Question No. 1

Which function or operator should you use to obtain the answer True or False to the question: "Do two variables refer to the same object?"

Show Answer Hide Answer
Correct Answer: D

To test whether two variables refer to the same object in memory, you should use theisoperator. Theisoperator returnsTrueif the two variables point to the same object in memory, andFalseotherwise.

For example:

a = [1, 2, 3]

b = a

c = [1, 2, 3]

print(a is b) # True

print(a is c) # False

In this example,aandbrefer to the same list object in memory, soa is breturnsTrue. On the other hand,aandcrefer to two separate list objects with the same values, soa is creturnsFalse.


Official Python documentation on Comparisons:https://docs.python.org/3/reference/expressions.html#not-in

Official Python documentation on Identity comparisons:https://docs.python.org/3/reference/expressions.html#is

Theisoperator is used to test whether two variables refer to the same object in memory. If two variablesxandyrefer to the same object, the expressionx is ywill evaluate toTrue. Otherwise, it will evaluate toFalse.

Question No. 2

Look at the following code snippets and decide which ones follow PEP 8 recommendations for whitespaces in expressions and statements (Select two answers.)

A)

No whitespace immediately before the opening parenthesis that starts the list of arguments of a function call:

B)

A whitespace immediately before a comma, semicolon, and colon:

C)

No whitespace between a trailing comma and a following closing parenthesis:

D)

A whitespace immediately after the opening parenthesis that starts indexing or slicing:

Show Answer Hide Answer
Question No. 3

What is a static method?

Show Answer Hide Answer
Correct Answer: C

A static method is a method that belongs to a class rather than an instance of the class. It is defined using the@staticmethoddecorator and does not take aselforclsparameter. Static methods are often used to define utility functions that do not depend on the state of an instance or the class itself.


Question No. 4

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

Show Answer Hide Answer
Correct 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 No. 5

Which one of the following methods allows you to debug an XML tree in the xml.etree ELementTree module?

Show Answer Hide Answer
Correct Answer: B

The dump() method in the xml.etree.ElementTree module allows you to output a debug representation of an XML tree to a file or standard output. This method is useful for analyzing the structure of the tree and tracking down errors.