Python Dictionary Quiz: Python Dictionary MCQs

Python Dictionary Quiz. MCQs related to Dictionary in Python Programming language.

 

Python Dictionary Quiz

 

 

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

a) Returns True if any key of the dictionary is true
b) Returns False if a dictionary is empty
c) Returns True if all keys of the dictionary are true
d) Method any() doesn’t exist for dictionary

 

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

>>> a={1:”A”,2:”B”,3:”C”}
>>> del a

a) method del doesn’t exist for the dictionary
b) del deletes the values in the dictionary
c) del deletes the entire dictionary
d) del deletes the keys in the dictionary

 

What will be the output of the following code ??

>>> a={}
>>> a.fromkeys([1,2,3],”check”)

a) Syntax error
b) {1:”check”,2:”check”,3:”check”}
c) “check”
d) {1:None,2:None,3:None}

 

Python Dictionary Quiz

 

Which of the statements about dictionary values if false ??

a) More than one key can have the same value
b) The values of the dictionary can be accessed as dict[key]
c) Values of a dictionary must be unique
d) Values of a dictionary can be a mixture of letters and numbers

 

What will be the output ??

>>> a={i: i*i for i in range(6)}
>>> a

a) Dictionary comprehension doesn’t exist
b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}
c) {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}
d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

 

What will be the output of following code ??

>>> a={‘B’:5,’A’:9,’C’:7}
>>> sorted(a)

a) [‘A’,’B’,’C’]
b) [‘B’,’C’,’A’]
c) [5,7,9]
d) [9,5,7]

 

Python Dictionary Quiz

 

What will be the output of the following ??

a={}
a[2]=1
a[1]=[2,3,4]
print(a[1][1])

a) [2,3,4]
b) 3
c) 2
d) An exception is thrown

 

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)

a) 25
b) 17
c) 16
d) Tuples can’t be made keys of a dictionary

 

The following Python code is invalid ??

class demo(dict):
def __test__(self,key):
return []
a = demo()
a[‘test’] = 7
print(a)

a) True
b) False

Leave a Comment

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

error: Content is protected !!