nerdexam
Python_Institute

PCEP-30-02 · Question #35

What is the expected output of the following code? ``python data = {} data['2'] = [1, 2] data['1'] = [3, 4] for i in data.keys(): print(data[i][i], end=' ') ``

The correct answer is A. 2 4. See the full explanation below for the reasoning.

Question

What is the expected output of the following code?
data = {}
data['2'] = [1, 2]
data['1'] = [3, 4]
for i in data.keys():
 print(data[i][i], end=' ')

Options

  • A2 4
  • B1 3
  • C3 1
  • D4 2

How the community answered

(34 responses)
  • A
    79% (27)
  • B
    3% (1)
  • C
    6% (2)
  • D
    12% (4)

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice