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

Page: 1 / 14
Total 45 questions
Question 1

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 2

Select the true statements related to PEP 8 naming conventions. (Select two answers.)



Answer : A, D

Option A is true because PEP 8 recommends that function and variable names should be lowercase, with words separated by underscores .

Option D is true because PEP 8 recommends that constants should be written in all capital letters with words separated by underscores .

PEP 8 is the official style guide for Python code. It provides guidelines for how to write readable code that follows consistent naming conventions. The aim of PEP 8 is to improve the readability of Python code and make it easier to understand and maintain.

According to PEP 8, variable and function names should be written in all lower-case letters with words separated by underscores, as stated in A. Constants, which are variables whose value is expected to remain constant throughout the code, should be written in all upper-case letters with words separated by underscores, as stated in D.


PEP 8 -- Style Guide for Python Code:https://www.python.org/dev/peps/pep-0008/

Python Documentation:https://docs.python.org/3/tutorial/classes.html#classmethods-and-staticmethods

Question 3

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



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.


Question 4

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)



Question 5

Select the true statements related to PEP 8 programming recommendations for code writing. (Select two answers:)



Question 6

What is true about the unbind_all () method?

(Select two answers.)



Answer : A, C

The unbind_all() method in Tkinter is used to remove all event bindings from a widget. It is a method of the widget object and can be called on any widget in the Tkinter application. Therefore, option A is the correct answer.

Option B is incorrect because the method can be called on any widget, not just the main window widget.

Option C is correct as unbind_all() does not take any parameters.

Option D is incorrect because the method only removes event bindings and does not cause the widgets to disappear.

So, the correct answers are A and C.


Tkinter documentation:https://docs.python.org/3/library/tkinter.html#event-bindings

Tkinter tutorial:https://www.python-course.eu/tkinter_events_binds.php

Question 7

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.


Page:    1 / 14   
Total 45 questions