Python_Institute
PCEP-30-02 · Question #371
What will be the output of the following code snippet? d = {} d[1] = 1 d['1'] = 2 d[1] += 1 sum = 0 for k in d: sum += d[k] print(sum)
The correct answer is C. 4. See the full explanation below for the reasoning.
Question
What will be the output of the following code snippet?
d = {}
d[1] = 1
d['1'] = 2
d[1] += 1
sum = 0
for k in d:
sum += d[k]
print(sum)
Options
- A3
- B2
- C4
- D1
How the community answered
(59 responses)- A15% (9)
- B3% (2)
- C75% (44)
- D7% (4)
Community Discussion
No community discussion yet for this question.