Check sibling questions

Predict the output of the following code if

mydict = {‘a’:23,'b': '78',’c’ :89, ‘d’:36}
>>>del mydict[‘c’]
>>>print mydict

(a) {‘a’:23,'b': '78',’c’ :89,‘d’:36}

(b) {‘a’:23,'b': '78',‘d’:36}

(c) {‘a’:23,'b': '78',89, ‘d’:36}

(d) {‘a’:23,'b': '78',’d’ :89, ‘e’:36}



  • The code uses the del statement to delete a key-value pair from a dictionary object in Python. 
  • del mydict[‘c’] means that the key ‘c’ and its associated value 89 are removed from the dictionary object named mydict.
  • The print statement prints the contents of the dictionary object to the standard output. 

Therefore, the output of the code is {‘a’: 23, ‘b’: ‘78’, ‘d’: 36} , which shows that the key ‘c’ and its value 89 are no longer present in the dictionary object named mydict.

So, the correct answer is (b) {‘a’:23,‘b’: ‘78’,‘d’:36}.

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.