nerdexam
Python_Institute

PCEP-30-02 · Question #16

``python 1 data = {'a': 1, 'b': 2, 'c': 3} 2 print(data['a'], 'b']) ``

The correct answer is B. The code is erroneous. Option B is correct because line 2 contains a SyntaxError: the closing square bracket ] in print(data['a'], 'b']) has no matching opening [, making the code impossible to parse - Python never even runs it. Why the distractors fail: A (1, 2) - plausible if you assume data['a']…

Question

1 data = {'a': 1, 'b': 2, 'c': 3}
2 print(data['a'], 'b'])

Options

  • A(1, 2)
  • BThe code is erroneous.
  • C('a':1, 'b':2)
  • D[1,2]

How the community answered

(36 responses)
  • A
    11% (4)
  • B
    72% (26)
  • C
    14% (5)
  • D
    3% (1)

Explanation

Option B is correct because line 2 contains a SyntaxError: the closing square bracket ] in print(data['a'], 'b']) has no matching opening [, making the code impossible to parse - Python never even runs it.

Why the distractors fail:

  • A (1, 2) - plausible if you assume data['a'] and data['b'] were both accessed correctly, but the broken syntax prevents any output.
  • C ('a':1, 'b':2) - Python never prints dict entries in that colon-separated format, and the code doesn't even attempt to print keys.
  • D [1, 2] - nothing in the code constructs or prints a list; the stray ] is a delimiter mismatch, not the start of a list literal.

Memory tip: Train your eye to scan for bracket balance - every [, (, and { needs a matching closer in the right order. A lone ] or ) with no opener is an instant SyntaxError, so the answer is always "erroneous" before you even think about the output.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice