nerdexam
Python_Institute

PCEP-30-02 · Question #169

What is the expected output of the following code? ``python def fun(): return True x = fun(false) print(x) ``

The correct answer is C. The program will cause an error. Option C is correct because Python's boolean literals are case-sensitive - the valid keyword is False (capitalized), not false. When Python tries to evaluate fun(false), it raises a NameError: name 'false' is not defined before the function even runs. And even if false were…

Question

What is the expected output of the following code?
def fun():
 return True

x = fun(false)
print(x)

Options

  • A0
  • BFalse
  • CThe program will cause an error.
  • DTrue
  • E1

How the community answered

(33 responses)
  • A
    12% (4)
  • C
    79% (26)
  • D
    3% (1)
  • E
    6% (2)

Explanation

Option C is correct because Python's boolean literals are case-sensitive - the valid keyword is False (capitalized), not false. When Python tries to evaluate fun(false), it raises a NameError: name 'false' is not defined before the function even runs. And even if false were corrected to False, a second error would occur: fun() is defined with no parameters, so passing any argument would raise a TypeError.

Why the distractors are wrong:

  • D (True): The function does contain return True, so this feels plausible - but execution never reaches the function body because the error halts the program first.
  • B (False): There is no path to False here; the function returns True, not False, making this doubly wrong.
  • A (0) and E (1): These exploit the fact that False == 0 and True == 1 in Python, tempting those who know booleans are integers - but again, the error prevents any output.

Memory tip: In Python, always capitalize booleans - True and False - just like you capitalize proper nouns in English. Lowercase true/false are JavaScript conventions; using them in Python always triggers a NameError.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice