1.

Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]?(a) Since “susan” is not a value in the set, Python raises a KeyError exception(b) It is executed fine and no exception is raised, and it returns None(c) Since “susan” is not a key in the set, Python raises a KeyError exception(d) Since “susan” is not a key in the set, Python raises a syntax errorI had been asked this question during an online exam.My query is from Dictionary in chapter Dictionary, Functions and Built-in Functions of Python

Answer»

Correct CHOICE is (c) Since “SUSAN” is not a key in the set, Python RAISES a KeyError exception

Easiest explanation - Execute in the shell to verify.



Discussion

No Comment Found

Related InterviewSolutions