R4RIN
MCQS
Python MCQ Quiz Hub
Dictionary Python MCQ set 2
Choose a topic to test your knowledge and improve your Python skills
1. 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.
D1.update(D2)
D2.update(D1)
D1.append(D2)
D2.append(D1)
2. 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.
D = {“Jan” : 31, “Feb” : 28, “Mar” : 31}
D = [“Jan”:31, “Feb”:28, “Mar”:31]
D = {“Jan” ; 31, “Feb” ; 28, “Mar” ; 31}
D = (“Jan”:31, “Feb”:28, “Mar”:31)
3. Write the output of the following: D={1: ['Amit',23,21], 2: ['Suman',45,34], 3: 'Ravi', 4: 'Anuj'} print("Amit" in D)
True
False
Error
None of the above
4. Which operator is used to check if the key is present in the dictionary or not?
Mathematical Operator
Relational Operator
Membership Operator
Logical Operator
5. 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])
. 34
45
m
Suman
6. 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’}
print(D.get(3))
print(D.get(3))
Both of the above
None of the above
7. Write the output of the following : D={1: 'Amit', 2: 'Suman', 3: 'Ravi', 4: 'Anuj'} print(tuple(D))
((1,”Amit”, (2, “Suman”), (3, “Ravi”), (4, “Anuj”))
(1, 2, 3, 4)
(“Amit”, “Suman”, “Ravi”, “Anuj”)
None of the above
Submit