PCEP-30-02 · Question #161
What is the default return value for a function that does not explicitly return any value?
The correct answer is D. None. In Python, when a function reaches its end without an explicit return statement, the interpreter automatically returns None - Python's built-in null/empty value representing the absence of a result. Why the distractors are wrong: A (void) - void is a keyword in statically-typed…
Question
Options
- Avoid
- BNull
- Cpublic
- DNone
- Eint
How the community answered
(24 responses)- A4% (1)
- C17% (4)
- D71% (17)
- E8% (2)
Explanation
In Python, when a function reaches its end without an explicit return statement, the interpreter automatically returns None - Python's built-in null/empty value representing the absence of a result.
Why the distractors are wrong:
- A (void) -
voidis a keyword in statically-typed languages like C, C++, and Java to declare that a function returns nothing; it doesn't exist in Python. - B (Null) -
Null(capitalized) is not a Python keyword; it's used in languages like Java (null) or SQL. Python usesNone, notNull. - C (public) -
publicis an access modifier from Java/C++; it has nothing to do with return values and doesn't exist in Python. - E (int) -
intis a data type, not a return value; no language automatically returns a zero integer from a function with no return statement.
Memory tip: Think "No return → None" - in Python, absence of an explicit return always gives you None, which you can verify by printing the result of any function that lacks a return statement.
Community Discussion
No community discussion yet for this question.