nerdexam
Python_Institute

PCEP-30-02 · Question #186

Which of the following lines properly starts a parameterless function definition?

The correct answer is B. def fun(). In Python, a function definition requires the def keyword, the function name, parentheses (even when there are no parameters), and a colon - making def fun(): the only valid syntax among the choices. Option A (def fun:) is missing the required parentheses; Python's parser…

Question

Which of the following lines properly starts a parameterless function definition?

Options

  • Adef fun:
  • Bdef fun():
  • Cfun function():
  • Dfunction fun():

How the community answered

(50 responses)
  • A
    8% (4)
  • B
    74% (37)
  • C
    4% (2)
  • D
    14% (7)

Explanation

In Python, a function definition requires the def keyword, the function name, parentheses (even when there are no parameters), and a colon - making def fun(): the only valid syntax among the choices.

Option A (def fun:) is missing the required parentheses; Python's parser expects them even for parameterless functions. Options C and D use function as a keyword, which belongs to JavaScript - Python never uses the word function.

Memory tip: Think "definitely need ( )" - every Python function definition must have parentheses after the name, no exceptions.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice