Computer Science

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

Python Dictionaries

5 Likes

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.

Answered By

1 Like


Related Questions