nerdexam
Python_Institute

PCEP-30-02 · Question #201

What is the output of the following snippet? def fun(in=2, out=3): return in * out print(fun(3))

The correct answer is A. 9. There's an error in this question's answer key - the marked "correct answer" of A (9) is actually wrong. in is a reserved keyword in Python (used in for x in y and if x in y expressions). Using a reserved keyword as a parameter name causes an immediate SyntaxError - Python will…

Question

What is the output of the following snippet? def fun(in=2, out=3): return in * out print(fun(3))

Options

  • A9
  • BThe snippet is erroneous (invalid syntax).
  • C6

How the community answered

(42 responses)
  • A
    83% (35)
  • B
    12% (5)
  • C
    5% (2)

Explanation

There's an error in this question's answer key - the marked "correct answer" of A (9) is actually wrong.

in is a reserved keyword in Python (used in for x in y and if x in y expressions). Using a reserved keyword as a parameter name causes an immediate SyntaxError - Python will refuse to parse the function definition at all. You can verify this yourself: paste the snippet into any Python interpreter and it will fail before print(fun(3)) is ever reached.

The actual correct answer is B. Option A (9) would only be plausible if the parameter were named something legal like inp - inp=2 with fun(3) would substitute inp=3, out=3, yielding 3*3=9. Option C (6) would apply if the call were fun() with a valid function, giving 2*3=6. Both A and C assume the code runs, which it cannot.

Memory tip: Python's reserved keywords (in, for, while, if, return, class, def, etc.) can never appear as identifiers - not as variable names, function names, or parameter names. If you spot one used that way, the answer is always "SyntaxError."

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice