QuestionQ72

VerifiedCoding Conventions, Best Practices, and Standardization

Review the following code snippets and identify which two of them correctly reflect PEP 8's recommendations regarding whitespace usage in expressions and statements.

Choose two
Explanation

PEP 8's guidance on whitespace in expressions and statements (the "Pet Peeves" section) explicitly states that whitespace should be avoided immediately before the open parenthesis that starts a function call's argument list — for example, spam(1) is correct, while spam (1) is not. It also explicitly states that no whitespace should appear between a trailing comma and a following closing parenthesis — for example, foo = (0,) is correct, while bar = (0, ) is not. By contrast, PEP 8 recommends avoiding whitespace immediately before a comma, semicolon, or colon (not adding it), and it recommends avoiding extraneous whitespace immediately inside/before brackets used for indexing or slicing (not adding whitespace after the opening bracket).

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!