WorksheetsQuiz on 19 Dec
Total questions: 10
Worksheet time: 3mins
1. Which of the following statements create a dictionary?
d = {}
d = {“john”:40, “peter”:45}
d = {40:”john”, 45:”peter”}
All of the mentioned
What will be the output of the following Python code snippet?
d = {"john":40, "peter":45}
"john" in d
True
False
None
Error
Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in the dictionary which command do we use?
d.size()
len(d)
size(d)
d.len()
What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
a.clear()
print(a)
None
{ None:None, None:None, None:None}
{1:None, 2:None, 3:None}
{ }
Output?
a={1:5,2:3,3:4}
print(a.pop(4,9))
9
3
Too many arguments
4
Output?
a={1:"A",2:"B",3:"C"}
for i in a:
print(i,end=" ")
1 2 3
‘A’ ‘B’ ‘C’
1 ‘A’ 2 ‘B’ 3 ‘C’
Error, it should be: for i in a.items():
output?
d1={"abc":5,"def":6,"ghi":7}
print(d1[0])
abc
5
{"abc":5}
Error
Which of the following will delete key_value pair for key="tiger" in the dictionary?
dic={"lion":"wild","tiger":"wild","cat":"domestic","dog":"domestic"}
del dic["tiger"]
dic["tiger"].delete()
delete(dic.["tiger"])
del(dic.["tiger"])
Which of these about a dictionary is false?
The values of a dictionary can be accessed using keys
The keys of a dictionary can be accessed using values
Dictionaries aren’t ordered
Dictionaries are mutable
Which of the following isn’t true about dictionary keys?
More than one key isn’t allowed
Keys must be immutable
Keys must be integers
When duplicate keys encountered, the last assignment wins
