Vidyalelo
Python · all questions

MCQs for Python Dictionaries: Exam
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

85

Questions

3/5

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following Python code?
>>> a=dict()
>>> a[1]

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
a.setdefault(4,"D")
print(a)

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={1:5,2:3,3:4}
print(a.pop(4,9))

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
>>> import collections
>>> a=collections.Counter([3,3,4,5])
>>> b=collections.Counter([3,4,4,5,5,5])
>>> a&b

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)

Select an option to see the answer and solution.

Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use?

Select an option to see the answer and solution.

The following Python code is invalid.
class demo(dict):
  def __test__(self,key):
    return []
a = demo()
a['test'] = 7
print(a)

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])

Select an option to see the answer and solution.

What will be the output of the following Python code?
>>> import collections
>>> a=dict()
>>> a=collections.defaultdict(str)
>>> a['A']

Select an option to see the answer and solution.

What will be the output of the following Python code?
count={}
count[(1,2,4)] = 5
count[(4,2,1)] = 7
count[(1,2)] = 6
count[(4,2,1)] = 2
tot = 0
for i in count:
    tot=tot+count[i]
print(len(count)+tot)

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
for i in a:
    print(i,end=" ")

Select an option to see the answer and solution.

Which of these about a dictionary is false?

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={1:5,2:3,3:4}
a.pop(3)
print(a)

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
>>>import collections
>>> a=collections.Counter([1,1,2,3,3,4,4,4])
>>> a

Select an option to see the answer and solution.

If b is a dictionary, what does any(b) do?

Select an option to see the answer and solution.

What will be the output of the following Python code snippet?
>>> a={1:"A",2:"B",3:"C"}
>>> del a

Select an option to see the answer and solution.

What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
a.clear()
print(a)

Select an option to see the answer and solution.