CBSE Class 11 Computer Science Question 34 of 112

Dictionaries — Question 14

Back to all questions
14
Question

Question 14

What would the following code print ?

d = {'spring':'autumn','autumn':'fall','fall':'spring'}
print(d['autumn'])
  1. autumn
  2. fall
  3. spring
  4. Error
Answer

fall

Reason — The values of dictionaries can be accessed by giving the key inside the square brackets of dictionary. The expression d['autumn'] will return "fall" as autumn is the key of dictionary d so d['autumn'] will return its value i.e., "fall".