nerdexam
Python_Institute

PCPP-32-101 · Question #57

Which of the following examples using line breaks and different indentation methods are compliant with PEP 8 recommendations? (Choose two.) A. B. C. D.

The correct answer is B. def my_function( var_one, var_two, var_three, var_four): pass D. def my_function(var_one, var_two): total = arg_a + arg_b # Four spaces for indentation. return total # Four spaces for indentation. Uses a hanging indent with four spaces for the continued argument lines, and the body is indented four spaces under the def, which matches PEP 8. Keeps the entire signature on one line and indents the body by four spaces, also compliant with

PEP and Best Practices

Question

Which of the following examples using line breaks and different indentation methods are compliant with PEP 8 recommendations? (Choose two.) A. B. C. D.

Exhibit

PCPP-32-101 question #57 exhibit

Options

  • A
    def foo(arg_a, arg_b):
        total = arg_a + arg_b  # Four spaces for indentation.
        return total  # One tab for indentation.
    
  • B
    def my_function(
            var_one, var_two,
            var_three, var_four):
        pass
    
  • C
    def my_function(
        var_one, var_two,
        var_three, var_four):
        pass
    
  • D
    def my_function(var_one, var_two):
        total = arg_a + arg_b  # Four spaces for indentation.
        return total  # Four spaces for indentation.
    

How the community answered

(27 responses)
  • A
    7% (2)
  • B
    89% (24)
  • C
    4% (1)

Explanation

Uses a hanging indent with four spaces for the continued argument lines, and the body is indented four spaces under the def, which matches PEP 8. Keeps the entire signature on one line and indents the body by four spaces, also compliant with

Topics

#PEP 8#line breaks#indentation#code style

Community Discussion

No community discussion yet for this question.

Full PCPP-32-101 Practice