CBSE Class 11 Computer Science Question 37 of 112

Dictionaries — Question 17

Back to all questions
17
Question

Question 17

What will be the result of the following code ?

d1 = {"abc":5,"def":6,"ghi":7} 
print(d1[0])
  1. abc
  2. 5
  3. {"abc":5}
  4. Error
Answer

Error

Reason — In Dictionaries, the elements are accessed through the keys defined in key:value pairs not by indexes, therefore the expression d1[0] will raise an error as "0" is no such key defined in d1.