🔍
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 error
0 like 0 dislike

1 Answer

c) Since “susan” is not a key in the set, Python raises a KeyError exception
0 like 0 dislike

Related questions

What will be the output? d1 = {"john":40, "peter":45} Page No 40 d2 = {"john":466, "peter":45} d1 == d2 a) True b) False c) None d) Error
Answer : b) False...

View solution
0 like 0 dislike
1 answer

Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use a) d.delete(“john”:40) b) d.delete(“john”) c) del d[“john”]. d) del d(“john”:40)
Answer : c) del d[“john”]....

View solution
0 like 0 dislike
1 answer

Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use? a) d.size() b) len(d) c) size(d) d) d.len()
Answer : b) len(d)...

View solution
0 like 0 dislike
1 answer

What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 > d2 a) True b) False c) Error d) None
Answer : Answer: c Explanation: Arithmetic > operator cannot be used with dictionaries....

View solution
0 like 0 dislike
1 answer

What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 == d2 a) True b) False c) None d) Error
Answer : Answer: b Explanation: If d2 was initialized as d2 = d1 the answer would be true....

View solution
0 like 0 dislike
1 answer

50.5k questions

47.1k answers

240 comments

7.0k users