Font size
WorksheetsPython dictionary
Total questions: 9
Worksheet time: 4mins
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
Given the dictionary person = {"name": "Alice", "age": 30}, how would you access Alice's age?
person[age]
person["Alice", "age"]
person.age
person["age"]
Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?
d.delete(“john”:40)
d.delete(“john”)
del d[“john”]
del d(“john”:40)
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
d["john"]
40
45
“john”
“peter”
Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.
True
False
Select the all correct way to remove the key ‘marks‘ from a dictionary
student = { "name": "Emma", "class": 9, "marks": 75 }
student.pop(“marks”)
del student[“marks”]
student.popitem()
dict1.remove(“key2”)
What is the output of the following dictionary operation
dict1 = {"name": "Mike", "salary": 8000}
temp = dict1.get("age")
print(temp)
KeyError: ‘age’
None
Select correct ways to create an empty dictionary
sampleDict = {}
sampleDict = dict()
sampleDict = dict{}
sampleDict = ()
