nerdexam
Python_Institute

PCEP-30-02 · Question #172

Which of the following lines correctly invoke the function defined below: (Choose two.) ``python def fun(a, b, c=0): # Body of the function. ``

The correct answer is A. fun(b=0, a=0) C. fun(0, 1, 2). A works because keyword arguments can be passed in any order - b=0, a=0 satisfies both required parameters, and c falls back to its default of 0. C works because all three parameters are filled positionally in order (a=0, b=1, c=2), which is straightforward and valid. B fails…

Question

Which of the following lines correctly invoke the function defined below: (Choose two.)
def fun(a, b, c=0):
 # Body of the function.

Options

  • Afun(b=0, a=0)
  • Bfun(b=1)
  • Cfun(0, 1, 2)
  • Dfun()

How the community answered

(58 responses)
  • A
    81% (47)
  • B
    14% (8)
  • D
    5% (3)

Explanation

A works because keyword arguments can be passed in any order - b=0, a=0 satisfies both required parameters, and c falls back to its default of 0. C works because all three parameters are filled positionally in order (a=0, b=1, c=2), which is straightforward and valid.

B fails because while b is named, a is never provided - Python will raise a TypeError: fun() missing 1 required positional argument: 'a'. D fails for the same reason: both a and b are required (no defaults), so calling fun() with no arguments is also a TypeError.

Memory tip: Count the parameters without default values - that's the minimum number of arguments you must always supply. Here, a and b have no defaults, so every valid call must account for both, either positionally or by name.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice