R4RIN
MCQS
Python MCQ Quiz Hub
Dictionary Python MCQ set 1
Choose a topic to test your knowledge and improve your Python skills
1. Keys of dictionary must be _______________
antique
unique
mutable
integers
2. Dictionaries in python are _______
Mutable data type
Non-Mutable data type
Mapping data type
Both a and c
3. Which of the following is used to delete an element from Dictionary?
pop( )
delete
remove
None of the above
4. Which statement is used to create an empty dictionary? a.
d1 = { }
d1 = ( )
d1 = dict{ }
d1 = [ ]
5. Dictionary is a ___________ data type.
Sequence
Mapping
Ordered
None of the above
6. Write the output of the following : d1 = {"a" : 50, "b" : 50} d2 = {"a" : 500, "b" : 50} print(d1 > d2)
True
False
Error
None of the above
7. Key – value concept is in ____
List
String
Dictionary
Tuple
8. In dictionary Keys and values are separated by ________________
Colon (:)
Comma( ,)
Semicolon(;)
dot(.)
9. All elements in dictionary are separated by _________
Semicolon(;)
Comma( ,)
Semicolon(;)
dot(.)
10. Which of the following is an example of dictionary?
L = [ ]
C = ( )
D = { }
None of the above
11. 1,2,3 are the ______________ in the following dictionary. D = {1 : “One”, 2 : “Two”, 3 : “Three”}
Keys
Values
Items
None of the above
12. Keys in dictionary are _____________ .
Mutable
Immutable
antique
integers
13. What type of error is returned by the following code : a={'a' : "Apple", 'b' : "Banana" , 'c' : "Cat"} print(a[1])
KeyError
KeyNotFoundError
NotFoundError
Syntax Error
14. Write the output of the following code : a={'a' : "Apple", 'b' : "Banana" , 'c' : "Cat"} a['a']="Anar" print(a)
{‘a’: ‘Anar’, ‘b’: ‘Banana’, ‘c’: ‘Cat’}
Error
{‘a’ : “Apple, ‘a’: ‘Anar’, ‘b’: ‘Banana’, ‘c’: ‘Cat’}
None of the above
15. Traversing a dictionary can be done using ____________
if statement
loop
jump statement
None of the above
16. The following code will return data as ______________
List
Tuple
Dictionary
None of the above
17. Write the output of the following code : A = {1 : "One", 2 : "Two", 3 : "Three"} B = {'A' : "Apple", 'B' : "Bat", 'C' : "Cat", 'D' : "Doll"} A.update(B) #print(B.values()) print(B)
{‘A’ : ‘Apple’ , ‘B’ : ‘Bat’ , ‘C’ : ‘Cat’ , ‘D’ : ‘Doll’}
{1 : “One” , 2 : “Two” , 3 : “Three”}
{1: ‘One’ , 2: ‘Two’ , 3: ‘Three’ , ‘A’: ‘Apple’ , ‘B’: ‘Bat’ , ‘C’: ‘Cat’ , ‘D’: ‘Doll’}
None of the above
18. Write the output of the following code : A = {1 : "One", 2 : "Two", 3 : "Three"} B = {'A' : "Apple", 'B' : "Bat", 'C' : "Cat", 'D' : "Doll"} print(A.get(4,"Key Not Found"))
KeyError
Key Not Found
None
Syntax Error
19. Write the output of the following: A = {1 : "One", 2 : "Two", 3 : "Three"} B = {'A' : "Apple", 'B' : "Bat", 'C' : "Cat", 'D' : "Doll"} for i in A: print(i)
1 2 3
1 2 3
{1 : “One”, 2 : “Two”, 3 : “Three”}
None of the above
20. Which statement is not correct in reference to the following code? A = {1 : "One", 2 : "Two", 3 : "Three"} A[4] = "Four"
It will add value at the end of dictionary.
It will modify value if the key already exist.
It will add value in between of the dictionary.
All the above
21. The following code is an example of _______ N = {A: {'name': 'Ravi', 'age': '5', 'sex': 'M'}, B: {'name': 'Golu', 'age': '2', 'sex': 'F'}}
Normal Dictionary
Nested Dictionary
Empty Dictionary
All the above
22. pop( ) function delete and ____ the element of dictionary.
display
return
not return
add
23. Which of the following is not method of dictionary?
len( )
pop( )
del ( )
update( )
24. Write the output of the following code : A = {1 : "One", 2 : "Two", 3 : "Three"} print(A[2] + A[1])
Error
TwoOne
21
{1 : “One”, 2 : “Two”, 3 : “Three”}
25. _______ datatype fall under mapping
List
Tuple
Dictionary
String
26. The key-value pair in dictionary is called ____
item
pair item
paired value
value
27. Choose the correct statement Assertion (A) : Items in dictionaries are unordered. Reason (R) : We may not get back the data in the same order in which we had entered the data initially in the dictionary.
A is true but R is false
A is false but R is true
Both A and R are false
Both A and R are true and R is the correct explanation of A
28. _______ is the suitable data type for keys of dictionary in python.
Number
String
Tuple
All the above
29. Choose the correct statement : Statement A : Dictionaries are mutable. Statement B : Contents of the dictionary can not changed after it has been created
Statement A is True
Statement B is True
Both the statements are True
Statement A is True and Statement B is False
30. Write the output of the following : A = {1 : "One", 2 : "Two", 3 : "Three"} print("One" in A)
True
False
Error
One
31. _________ function returns the number of key: value pairs of the dictionary.
total( )
len( )
length( )
items( )
32. Which of the following function create a dictionary from a sequence of key-value pairs
dictionary( )
dict( )
create( )
convert( )
33. Following statement return values in the form of _______ >>> D1.keys() #D1 is a dictionary
tuple
list
string
dictionary
34. Which of the following is feature of Dictionary?
Keys are unique within a dictionary.
Keys are unique within a dictionary.
Dictionary is mutable.
All of the above
35. Which of the following is feature of Dictionary?
Keys are unique within a dictionary.
Keys are unique within a dictionary.
Dictionary is mutable.
All of the above
36. Which of the following is feature of Dictionary?
Keys are unique within a dictionary.
Keys are unique within a dictionary.
Dictionary is mutable.
All of the above
37. Which of the following is feature of Dictionary?
Keys are unique within a dictionary.
Keys are unique within a dictionary.
Dictionary is mutable.
All of the above
38. Which of the following is feature of Dictionary?
Keys are unique within a dictionary.
Keys are unique within a dictionary.
Dictionary is mutable.
All of the above
39. A = {“A” : “Apple”, “B” : “Ball”, “C” : “Cat”} Which of the following statement will return : dict_items([(‘A’, ‘Apple’), (‘B’, ‘Ball’), (‘C’, ‘Cat’)])
print(A.keys( ))
print(A.values( ))
print(A.Items( ))
print(A.get( ))
40. Which of the following are immutable data type? a. String b. Tuple c. List d. Dictionary
a and c
b and d
a and b
c and d
41. _________ function returns the value corresponding to the key passed as the argument.
get( )
values( )
update( )
update( )
42. Write the output of the following : A = {"A" : "Apple", "B" : "Ball", "C" : "Cat"} print(A.get("D"))
KeyNotFoundError
Name Error
Type Error
None
43. Which function helps to merge dictionary ‘D1’ and ‘D2’?
merge( )
append( )
update( )
get( )
Submit