nerdexam
Python_Institute

PCEP-30-02 · Question #221

Consider the following code. ``python def func(x=0): return x `` With sentence describes the function the best? A function defined like function()...

The correct answer is C. may be called without any argument, or with just one. Option C is correct because x=0 is a default parameter - Python allows you to call func() with no argument (using the default 0) or with exactly one argument like func(5), overriding the default. Why the distractors are wrong: A is wrong - the function never requires an…

Question

Consider the following code.
def func(x=0):
 return x

With sentence describes the function the best? A function defined like function()...

Options

  • Amust be called with exactly one argument.
  • Bmay be called with any number of arguments (including zero).
  • Cmay be called without any argument, or with just one.
  • Dmust be called without arguments.

How the community answered

(43 responses)
  • A
    2% (1)
  • B
    12% (5)
  • C
    79% (34)
  • D
    7% (3)

Explanation

Option C is correct because x=0 is a default parameter - Python allows you to call func() with no argument (using the default 0) or with exactly one argument like func(5), overriding the default.

Why the distractors are wrong:

  • A is wrong - the function never requires an argument since a default is provided.
  • B is wrong - func(1, 2) would raise a TypeError; the function only accepts zero or one argument, not any number.
  • D is wrong - you can pass an argument; func(42) is perfectly valid.

Memory tip: Think of the = in x=0 as a "safety net" - if no argument is thrown, the net catches it with the default value. A default parameter makes the argument optional, not forbidden and not unlimited.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice