exam questions

Exam PCPP-32-101 All Questions

View all questions & answers for the PCPP-32-101 exam

Exam PCPP-32-101 topic 1 question 21 discussion

Actual exam question from Python Institute's PCPP-32-101
Question #: 21
Topic #: 1
[All PCPP-32-101 Questions]

Select the true statement about PEP 8 recommendations related to line breaks and binary operators.

  • A. It is recommended that you use line breaks before binary operators to improve code readability
  • B. It is permissible to use line breaks before or after a binary operator, as long as the convention is consistent locally. However, for new code, it is recommended that break lines should be used only after binary operators.
  • C. It is recommended that you use line breaks after binary operators to improve code readability
  • D. There is no specific PEP 8 recommendation related to using line breaks with binary operators
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
86f110d
1 month, 1 week ago
Selected Answer: B
The most accurate and comprehensive statement is B, as it fully captures PEP 8's nuanced recommendation: it is permissible to break before or after binary operators if consistent locally, but for new code, breaking after operators is preferred. Option C is also true but less detailed, while A and D are incorrect. Since the question asks for the true statement (singular), but the context implies selecting the best representation of PEP 8's intent, B is the most precise. However, if forced to choose two due to a potential oversight in the question's phrasing (noted as "Choose two" in prior questions), B and C could be considered, though B alone is sufficient for accuracy.
upvoted 1 times
...
Stokvisss
3 months, 3 weeks ago
Selected Answer: B
In Python code, it is permissible to break before or after a binary operator, as long as the convention is consistent locally. For new code Knuth’s style (breaking before the operator) is suggested.
upvoted 1 times
...
sousouka
4 months ago
Selected Answer: A
To solve this readability problem, mathematicians and their publishers follow the opposite convention. Donald Knuth explains the traditional rule in his Computers and Typesetting series: “Although formulas within a paragraph always break after binary operations and relations, displayed formulas always break before binary operations” [3]. Following the tradition from mathematics usually results in more readable code: # Correct: # easy to match operators with operands income = (gross_wages + taxable_interest + (dividends - qualified_dividends) - ira_deduction - student_loan_interest) In Python code, it is permissible to break before or after a binary operator, as long as the convention is consistent locally. For new code Knuth’s style is suggested.
upvoted 1 times
...
claudiupopa
4 months, 1 week ago
Selected Answer: B
PEP 8 allows line breaks either before or after binary operators, as long as the style is consistent within the project or local context. For new code, PEP 8 recommends breaking lines after binary operators to improve readability and align with mathematical notation. Example of the recommended style: result = (variable1 + variable2 - variable3)
upvoted 1 times
...
Moneybing
7 months ago
Selected Answer: A
PEP8 now (since 2016-06-08) recommends breaking before the binary operator. Even though in Python you’re allowed to break code lines before or after binary operators (providing you do so consistently and that this convention has been used in your code before), it is recommended that you follow Donald Knuth’s style suggestions and break before binary operators as this results in a more readable, eye-friendly code. https://edube.org/learn/pcpp1-python-enhancement-proposals-peps/pep-8-code-layout-1
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago