11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
HOME Interview Questions MCQs *LAB VIVA CLASS NOTES SEMINAR TOPICS ONLINE TEST GATE CAT Internship
ABOUT US Privacy Policy
Any Skill Search He
GouMax
Optical Communications
We Develop High-End Optical Components and Modules for Test and Measurement Solutions.
goumax.com OPEN
Home » Python Objective Questions » 250+ TOP MCQs on Python Dictionary and Answers
250+ TOP MCQs on Python Dictionary and
Answers
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 1/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
llipaat
Intellipaat
Latest Home Interior Designs
For Your New 2/3/4 BHK Home
Design, explore, imagine and more with the home interiors experts. 45 Days Delivery.
Data
Science
& AI
homelane.com OPEN
Python Multiple Choice Questions on “Dictionary – 2”. Program
1. Which of these about a dictionary is false?
a) The values of a dictionary can be accessed using keys
Intellipaat
b) The keys of a dictionary can be accessed using values
c) Dictionaries aren’t ordered
d) Dictionaries are mutable
Answer: b
Clarification: The values of a dictionary can be accessed using keys but the keys of a dictionary can’t
be accessed using values.
Open
2. 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) { }
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 2/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
Answer: c
Clarification: Option c is a set, not a dictionary.
3. 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”
Answer: a
Clarification: In the above code, variables i and j iterate over the keys and values of the dictionary
respectively.
4. 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
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 3/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
c) 4
d) Invalid syntax for get method
Answer: b
Clarification: The get() method returns the value of the key if the key is present in the dictionary
and the default value(second parameter) if the key isn’t present in the dictionary.
5. 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
Answer: d
Clarification: The get() method returns the default value(second parameter) if the key isn’t present
in the dictionary.
6. What will be the output of the following Python code snippet?
a={1:"A",2:"B",3:"C"}
print(a.setdefault(3))
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 4/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
a) {1: ‘A’, 2: ‘B’, 3: ‘C’}
b) C
c) {1: 3, 2: 3, 3: 3}
d) No method called setdefault() exists for dictionary
Answer: b
Clarification: setdefault() is similar to get() but will set dict[key]=default if key is not already in the
dictionary.
7. 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]
Answer: a
Clarification: setdefault() will set dict[key]=default if key is not already in the dictionary.
8. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 5/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
a.update(b)
print(a)
a) {1: ‘A’, 2: ‘B’, 3: ‘C’}
b) Method update() doesn’t exist for dictionaries
c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
d) {4: ‘D’, 5: ‘E’}
Answer: c
Clarification: update() method adds dictionary b’s key-value pairs to dictionary a. Execute in
python shell to verify.
9. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
b=a.copy()
b[2]="D"
print(a)
a) Error, copy() method doesn’t exist for dictionaries
b) {1: ‘A’, 2: ‘B’, 3: ‘C’}
c) {1: ‘A’, 2: ‘D’, 3: ‘C’}
d) “None” is printed
Answer: b
Clarification: Changes made in the copy of the dictionary isn’t reflected in the original one.
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 6/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
10. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
a.clear()
print(a)
a) None
b) { None:None, None:None, None:None}
c) {1:None, 2:None, 3:None}
d) { }
Answer: d
Clarification: The clear() method clears all the key-value pairs in the dictionary.
11. Which of the following isn’t true about dictionary keys?
a) More than one key isn’t allowed
b) Keys must be immutable
c) Keys must be integers
d) When duplicate keys encountered, the last assignment wins
Answer: c
Clarification: Keys of a dictionary may be any data type that is immutable.
12. What will be the output of the following Python code?
a={1:5,2:3,3:4}
a.pop(3)
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 7/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
print(a)
a) {1: 5}
b) {1: 5, 2: 3}
c) Error, syntax error for pop() method
d) {1: 5, 3: 4}
Answer: b
Clarification: pop() method removes the key-value pair for the key mentioned in the pop() method.
13. What will be the output of the following Python code?
a={1:5,2:3,3:4}
print(a.pop(4,9))
a) 9
b) 3
c) Too many arguments for pop() method
d) 4
Answer: a
Clarification: pop() method returns the value when the key is passed as an argument and otherwise
returns the default value(second argument) if the key isn’t present in the dictionary.
14. What will be the output of the following Python code?
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 8/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
a={1:"A",2:"B",3:"C"}
for i in a:
print(i,end=" ")
a) 1 2 3
b) ‘A’ ‘B’ ‘C’
c) 1 ‘A’ 2 ‘B’ 3 ‘C’
d) Error, it should be: for i in a.items():
Answer: a
Clarification: The variable i iterates over the keys of the dictionary and hence the keys are printed.
15. What will be the output of the following Python code?
>>> a={1:"A",2:"B",3:"C"}
>>> a.items()
a) Syntax error
b) dict_items([(‘A’), (‘B’), (‘C’)])
c) dict_items([(1,2,3)])
d) dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
Answer: d
Clarification: The method items() returns list of tuples with each tuple having a key-value pair.
---- >> Related Posts Of Above Questions :::
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 9/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
------>>[MOST IMPORTANT]<<------
1. 250+ TOP MCQs on Python Dictionary and Answers
2. 250+ TOP MCQs on Python Dictionary and Answers
3. 250+ TOP MCQs on Python Dictionary and Answers
4. 250+ TOP MCQs on Python Sets and Answers
5. 250+ TOP MCQs on Python Sets and Answers
6. 250+ TOP MCQs on Python While and For Loops and Answers
7. 250+ TOP MCQs on Python Tuples-3 and Answers
8. 300+ TOP Python Programming Language Interview Questions with Answers
9. 250+ TOP MCQs on Python Function and Answers
10. 250+ TOP MCQs on Python Python Modules and Answers
11. 250+ TOP MCQs on Python Global vs Local Variables and Answers
12. 250+ TOP MCQs on Python Formatting and Answers
13. 250+ TOP MCQs on Python Core Data types and Answers
14. 250+ TOP MCQs on Python Tuples and Answers
15. [TIPS] Top 20 Python Interview questions to win in a job interview
16. 250+ TOP MCQs on Python Sets and Answers
17. 250+ TOP MCQs on Python Strings and Answers
18. 250+ TOP MCQs on Python Strings and Answers
19. 250+ TOP MCQs on Python List Comprehension and Answers
20. 250+ TOP MCQs on Java.util – Dictionary, Hashtable & Properties and
Answers
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 10/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
LEAVE A REPLY
Your email address will not be published. Required fields are marked *
Comment
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 11/12
11/15/21, 2:04 PM 250+ TOP MCQs on Python Dictionary and Answers
Name *
Email *
Website
Post Comment
Engineering 2021 , Engineering Interview Questions.com , Theme by Engineering||
Privacy Policy||
Terms and Conditions||
ABOUT US||
Contact US||
Engineering interview questions,Mcqs,Objective Questions,Class Lecture Notes,Seminor topics,Lab Viva Pdf PPT Doc Book free download. Most
Asked Technical Basic CIVIL | Mechanical | CSE | EEE | ECE | IT | Chemical | Medical MBBS Jobs Online Quiz Tests for Freshers Experienced .
https://engineeringinterviewquestions.com/mcqs-on-dictionary-2-answers/ 12/12