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
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)- A4% (1)
- B4% (1)
- C77% (20)
- D15% (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)) -levelhas no default, so Python raises aTypeErrorif called without it. - B (
delta(level, size=0)) -sizehas a default, butleveldoes not, sodelta()still fails; you'd need at leastdelta(some_value). - D (
def beta(None)) - this is a syntax error;Noneis 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.