PCPP1 practice question 10 of 10
Select the true statement related to PEP 257.
Full set: 45 questionsPEP 257, "Docstring Conventions," extends the concept of docstrings beyond the standard doc attribute attached to modules, functions, classes, and methods. It specifies two other types of docstrings that are not assigned to doc but can be processed by documentation tools. "Attribute docstrings" are string literals immediately following a public attribute assignment. "Additional docstrings" are string literals that appear immediately after another docstring. The PEP explicitly states that software tools may extract both of these for documentation purposes, making them recognized conventions.
A. String literals immediately after another docstring are called "additional docstrings," not "attribute docstrings." Attribute docstrings follow an attribute assignment.
C. Only a string literal that is the first statement in a module, function, or class is recognized by the compiler as a docstring and assigned to the doc attribute.
D. The term for a docstring following a top-level assignment is "attribute docstring." PEP 257 does not define or use the term "complementary docstrings."
1. Python Enhancement Proposals (PEP) 257: This document is the primary source for docstring conventions.
For Correct Answer B: The sections "Attribute Docstrings" and "Additional Docstrings" explicitly define these types and note: "Docstring processing tools may extract attribute docstrings..." and "These docstrings may be extracted by software tools." (Source: https://peps.python.org/pep-0257/)
For Incorrect Option A & D: The section "Attribute Docstrings" defines them as following an assignment, and the section "Additional Docstrings" defines them as following another docstring, clarifying the terminology. (Source: https://peps.python.org/pep-0257/)
2. The Python Language Reference, Section 8.7 "Function definitions": This official documentation confirms that a docstring must be the first statement in a definition body.
For Incorrect Option C: "The first statement of the function body can optionally be a string literal; this string literal is the function’s documentation string, or docstring." This clarifies that subsequent string literals are not treated as the primary docstring. (Source: https://docs.python.org/3/reference/compoundstmts.html#function-definitions)
3. MIT OpenCourseWare, 6.0001 Introduction to Computer Science and Programming in Python, Fall 2016, Lecture 5 Notes: University courseware reinforces the fundamental definition of a docstring.
For Incorrect Option C: The notes on "Specifications" for functions state, "In Python, we add a string as the first line of the function body" to serve as the docstring, confirming its required position. (Source: https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/lec5functions/, Section: "Specifications")
Keep practicing
Take the free PCPP1 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other PCPP1 practice questions
- Question 1Select the true statements about the connection-oriented and connectionless types of comm…
- Question 2Select the true statements about the sqlite3 module. (Select two answers.)
- Question 4Select the true statements about the sqirte3 module. (Select two answers.)
- Question 5If w is a correctly created main application window, which method would you use to foe bo…
- Question 7Select the true statements about the json.-dumps () function. (Select two answers.)
- Question 9Select the true statements related to PEP 8 naming conventions. (Select two answers.)
