Python Dictionary Interview Questions: Python MCQs

Python Dictionary Interview Questions. Multiple Choice Questions related to Dictionary in Python. 

 

Python Dictionary Interview Questions

 

 

What will be the output of the following Python code snippet ??

a={1:”A”,2:”B”,3:”C”}
a.setdefault(4,”D”)
print(a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’}
b) None
c) Error
d) [1,3,6,10]

 

What will be the output of the following Python code snippet ??

d = {“john”:40, “peter”:45}
“john” in d

a) True
b) False
c) None
d) Error

 

What will be the output of the following Python code snippet ??

a={1:”A”,2:”B”,3:”C”}
print(a.setdefault(3))

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}
b) C
c) {1: 3, 2: 3, 3: 3}
d) No method called setdefault() exists for dictionary

 

What will be the output of the following Python code ??

d = {“john”:40, “peter”:45}

a) “john”, 40, 45, and “peter”
b) “john” and “peter”
c) 40 and 45
d) d = (40:”john”, 45:”peter”)

 

Python Dictionary Interview Questions

 

What will be the output of the following Python code snippet ??

a={1:”A”,2:”B”,3:”C”}
print(a.get(5,4))

a) Error, invalid syntax
b) A
c) 5
d) 4

 

Which of the following statements create a dictionary ??

a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
d) All of the mentioned

 

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

a) Counter({3: 12, 4: 1, 5: 1})
b) Counter({3: 1, 4: 1, 5: 1})
c) Counter({4: 2})
d) Counter({5: 1})

 

What will be the output of the following Python code snippet ??

a={1:”A”,2:”B”,3:”C”}
print(a.get(1,4))

a) 1
b) A
c) 4
d) Invalid syntax for get method

 

Python Dictionary Interview Questions

 

What will be the output of the following Python code snippet ??

>>> import collections
>>> a=collections.Counter([2,2,3,3,3,4])
>>> b=collections.Counter([2,2,3,4,4])
>>> a|b

a) Counter({3: 3, 2: 2, 4: 2})
b) Counter({2: 2, 3: 1, 4: 1})
c) Counter({3: 2})
d) Counter({4: 1})

 

What will be the output of the following Python code snippet ??

a={1:”A”,2:”B”,3:”C”}
for i,j in a.items():
print(i,j,end=” “)

a) 1 A 2 B 3 C
b) 1 2 3
c) A B C
d) 1:”A” 2:”B” 3:”C”

 

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)

a) Counter({4: 3, 2: 2, 3: 1})
b) {3:1}
c) {4:3}
d) [(4, 3)]

 

Which of the following is not a declaration of the dictionary ??

a) {1: ‘A’, 2: ‘B’}
b) dict([[1,”A”],[2,”B”]])
c) {1,”A”,2”B”}
d) { }

 

Python Dictionary Interview Questions

 

What will be the output of the following code ??

>>>import collections
>>> b=collections.Counter([2,2,3,4,4,4])
>>> b.most_common(1)

a) Counter({4: 3, 2: 2, 3: 1})
b) {3:1}
c) {4:3}
d) [(4, 3)]

 

Which of these about a dictionary is false ??

a) The values of a dictionary can be accessed using keys
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable

 

What will be the output of the following Python ??

>>>import collections
>>> a=collections.Counter([1,1,2,3,3,4,4,4])
>>> a

a) {1,2,3,4}
b) Counter({4, 1, 3, 2})
c) Counter({4: 3, 1: 2, 3: 2, 2: 1})
d) {4: 3, 1: 2, 3: 2, 2: 1}

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!