nerdexam
Python_Institute

PCEP-30-02 · Question #192

The following snippet: def func(a, b): return b ** a print(func(b=2, 2))

The correct answer is B. is erroneous. Option B is correct because func(b=2, 2) raises a SyntaxError before the code even executes - Python requires all positional arguments to appear before keyword arguments in a function call, and placing 2 (positional) after b=2 (keyword) violates this rule. Why the distractors…

Question

The following snippet: def func(a, b): return b ** a print(func(b=2, 2))

Options

  • Awill output 4
  • Bis erroneous
  • Cwill output None
  • Dwill output 2

How the community answered

(26 responses)
  • A
    8% (2)
  • B
    77% (20)
  • C
    12% (3)
  • D
    4% (1)

Explanation

Option B is correct because func(b=2, 2) raises a SyntaxError before the code even executes - Python requires all positional arguments to appear before keyword arguments in a function call, and placing 2 (positional) after b=2 (keyword) violates this rule.

Why the distractors are wrong:

  • A (output 4): Tempting because 2 ** 2 = 4, but the call is syntactically invalid and the function never runs.
  • C (output None): Wrong on two counts - the syntax error prevents execution, and even if it ran, the function explicitly returns a value (b ** a), not None.
  • D (output 2): Incorrect arithmetic even in a hypothetical valid call; 2 ** 2 is 4, not 2.

Memory tip: Think "Positional before Keyword" - PIK (like "pick" your order carefully). Once you name an argument, all remaining arguments must also be named; you can't "go back" to positional after using a keyword.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice