nerdexam
Python_Institute

PCEP-30-02 · Question #199

Which of the following function calls can be used to invoke the below function definition? (Choose three.) def test(a, b, c, d):

The correct answer is B. test(1, 2, 3, d=4) D. test(1, 2, 3, 4) E. test(a=1, b=2, c=3, d=4). B, D, and E are correct because Python allows function arguments to be passed entirely by position (D), entirely by keyword (E), or as a mix where positional arguments come first and keyword arguments follow (B). In B, 1, 2, 3 fill a, b, c positionally, then d=4 is specified by…

Question

Which of the following function calls can be used to invoke the below function definition? (Choose three.) def test(a, b, c, d):

Options

  • Atest(a=1, b=2, c=3, 4)
  • Btest(1, 2, 3, d=4)
  • Ctest(a=1, 2, 3, 4)
  • Dtest(1, 2, 3, 4)
  • Etest(a=1, b=2, c=3, d=4)
  • Ftest(a=1, 2, c=3, d=4)

How the community answered

(24 responses)
  • A
    13% (3)
  • B
    79% (19)
  • C
    4% (1)
  • F
    4% (1)

Explanation

B, D, and E are correct because Python allows function arguments to be passed entirely by position (D), entirely by keyword (E), or as a mix where positional arguments come first and keyword arguments follow (B). In B, 1, 2, 3 fill a, b, c positionally, then d=4 is specified by name - a perfectly valid hybrid.

A, C, and F are all wrong for the same core reason: Python's syntax rule states that positional arguments cannot follow keyword arguments. In A, 4 is a bare positional that comes after a=1, b=2, c=3. In C, 2, 3, 4 are positional but appear after a=1. In F, the positional 2 appears between keyword arguments a=1 and c=3. All three raise a SyntaxError: positional argument follows keyword argument.

Memory tip: Think of it as a one-way door - once you switch to keyword arguments in a call, you must stay with keywords for the rest of the call. "Keywords can trail positions, but positions can't trail keywords."

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice