KnowledgeBoat Logo
|

Computer Science

What would the following code print ?

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

Python Dictionaries

4 Likes

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".

Answered By

1 Like


Related Questions