Python Test 9 - Dictionary Which of the following statements create a dictionary? d = {“john”:40, “peter”:45} d = {40:”john”, 45:”peter”} d = {} All of the mentioned What will be the output of the following Python code snippet? d = {"john":40, "peter":45} “john” and “peter” “john”, 40, 45, and “peter” 40 and 45 d = (40:”john”, 45:”peter”) What will be the output of the following Python code snippet? d = {"john":40, "peter":45} "john" in d Error None False True What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 == d2 Error False True None What will be the output of the following Python code snippet? d1 = {"john":40, "peter":45} d2 = {"john":466, "peter":45} d1 > d2 None True False Error What will be the output of the following Python code snippet? d = {"john":40, "peter":45} d["john"] “peter” “john” 45 40 Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use? del d(“john”:40) del d[“john”] d.delete(“john”) d.delete(“john”:40) Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use? len(d) d.size() d.len() size(d) What will be the output of the following Python code snippet? d = {"john":40, "peter":45} print(list(d.keys())) (“john”:40, “peter”:45) [“john”, “peter”] [“john”:40, “peter”:45] (“john”, “peter”) Suppose d = {“john”:40, “peter”:45}, what happens when we try to retrieve a value using the expression d[“susan”]? Since “susan” is not a key in the set, Python raises a syntax error Since “susan” is not a key in the set, Python raises a KeyError exception Since “susan” is not a value in the set, Python raises a KeyError exception It is executed fine and no exception is raised, and it returns None Schreibe einen Kommentar Antworten abbrechenDu musst angemeldet sein, um einen Kommentar abzugeben.