MCQ on Dictionary in Python - QNS
MCQ on Dictionary in Python - QNS
HARIKRISHNAN A S
[email protected]
Q1. Keys of dictionary must be
a. antique b. unique c. mutable d. integers
Q8. Dictionaries are flexible in nature, means elements can be added or removed from it.
a. True b. False
1|Page
Q17. Keys in dictionary are _____________ .
a. Mutable b. Immutable c. antique d. integers
1 1
2 2
3 3
2|Page
Q25. Which statement is not correct in reference to the following code?
A = {1 : "One", 2 : "Two", 3 : "Three"}
A[4] = "Four"
a. It will add value at the end of dictionary.
b. It will modify value if the key already exist.
c. It will add value in between of the dictionary.
d. All of the above
Q34. _________ is the suitable data type for keys of dictionary in python.
a. Number b. String c. Tuple d. All of the above
3|Page
Q36. Write the output of the following :
A = {1 : "One", 2 : "Two", 3 : "Three"}
print("One" in A)
a. True b. False c. Error d. One
Q38. ___________ function returns the number of key: value pairs of the dictionary.
a. total( ) b. len( ) c. length( ) d. items( )
Q39. Which of the following function create a dictionary from a sequence of key-value
pairs
a. dictionary( ) b. dict( ) c. create( ) d. convert( )
Q44. __________ function returns the value corresponding to the key passed as the
argument.
a. get( ) b. values( ) c. update( ) d. del( )
4|Page
Q48. Which function/statement delete all the items of the dictionary?
a. clear( ) b. del c. delete( ) d. pop( )
Q50. Write a statement to retrieve the value corresponding to the key 7 in dictionary
‘D1’.
a. D1.get(7) b. D1.values(7) c. D1.pop(7) d. D1.disp(7)
Q52. Aman wants to convert the sequence given below to dictionary. Which of the
following function will help him to convert?
((1,”Amit”),(2,”Suman”),(3,”Ravi”))
a. dict( ) b. dictionary( ) c. tuple( ) d. convert( )
Q55. Which of the statement will delete third item (3: ‘Ravi’) from dictionary given below:
D={1: ‘Amit’, 2: ‘Suman’, 3: ‘Ravi’, 4: ‘Anuj’}
a. D.pop(3) b. del D[3] c. Both of the above d. D.clear(3)
Q57. Parth wants to display the value corresponding to the key “3” in dictionary given
below. As a friend of Parth, help him to find the correct code.
D={1: ‘Amit’, 2: ‘Suman’, 3: ‘Ravi’, 4: ‘Anuj’}
a. print(D.get(3)) b. print(D[3]) c. Both of the above d. None of the above
5|Page
Q58. Write the output of the following:
D={1: ['Amit',23,21], 2: ['Suman',45,34], 3: 'Ravi', 4: 'Anuj'}
m = D.get(2)
print(m[2])
a. 34 b. 45 c. m d. Suman
Q59. Which operator is used to check if the key is present in the dictionary or not?
a. Mathematical Operator b. Relational Operator
c. Membership Operator d. Logical Operator
Q61. Anshu created two dictionaries “D1” and “D2” in python. Later on she wants to add
all the elements of D2 in D1. As a friend of Anshu, help her to write the code.
a. D1.update(D2) b. D2.update(D1)
c. D1.append(D2) d. D2.append(D1)
Q62. Dhriti wants to create a dictionary with “Jan”, “Feb”, “Mar” as key and 31, 28, 31
as values respectively. Help her to write the correct code.
a. D = {“Jan” : 31, “Feb” : 28, “Mar” : 31} b. D = [“Jan”:31, “Feb”:28, “Mar”:31]
c. D = {“Jan” ; 31, “Feb” ; 28, “Mar” ; 31} d. D = (“Jan”:31, “Feb”:28, “Mar”:31)
6|Page