Font size
WorksheetsPython Quiz 2.0
Total questions: 14
Worksheet time: 8mins
A dictionary is an example of a sequence ...
True
False
A Python dictionary stores ...
value - key pairs
key - value pairs
Which of the following create an empty dictionary (D)?
D = dict()
D = ()
D = []
D = {}
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
quiz = ("Do you help out at home? ":"yes" }
You have the following dictionary definition:
d = {'foo': 100, 'bar': 200, 'baz': 300}
What method call will delete the entry whose value is 200?
delete d('bar')
d.pop("bar")
d.remove("bar")
None of the above
Which method will remove an element the Dictionary data type?
.pop()
.discard()
.remove()
Please select all correct ways to empty the following dictionary
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
del student
del student[0:2]
student.clear()
Items are accessed by their position in a dictionary
True
False
_________________ method will not only delete the item from dictionary, but also return the deleted value.
del ( )
pop( )
Clear( )
________________method will returns number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
Which of the following will give error?
Suppose dict1={"a":1,"b":2,"c":3}
print(len(dict1))
print(dict1.get("b"))
dict1["a"]=5
None of these.
What would be the output of the following code snippet?
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
d_items = a_dict.items()
print(d_items)
('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')
dict_items([('color'), ('fruit'), ('pet')])
[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]
dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])
