nerdexam
Python_Institute

PCEP-30-02 · Question #349

Which of the following functions can be invoked without arguments?

The correct answer is C. def alpha(level=100): pass. alpha(level=100) can be called as simply alpha() because level has a default value of 100, making the argument optional - Python automatically uses the default when no argument is supplied. Why the distractors fail: A (gamma(level)) - level has no default, so Python raises a…

Question

Which of the following functions can be invoked without arguments?

Options

  • Adef gamma(level): pass
  • Bdef delta(level, size = 0): pass
  • Cdef alpha(level=100): pass
  • Ddef beta(None): pass

How the community answered

(26 responses)
  • A
    4% (1)
  • B
    4% (1)
  • C
    77% (20)
  • D
    15% (4)

Explanation

alpha(level=100) can be called as simply alpha() because level has a default value of 100, making the argument optional - Python automatically uses the default when no argument is supplied.

Why the distractors fail:

  • A (gamma(level)) - level has no default, so Python raises a TypeError if called without it.
  • B (delta(level, size=0)) - size has a default, but level does not, so delta() still fails; you'd need at least delta(some_value).
  • D (def beta(None)) - this is a syntax error; None is a keyword, not a valid parameter name.

Memory tip: A parameter without = is required; a parameter with = is optional. To call a function with zero arguments, every parameter must have a default value - one bare required parameter breaks the whole call.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice