Python Programming - Dictionaries
Exercise : Dictionaries - General Questions
- Dictionaries - General Questions
6.
How do you merge two dictionaries?
Answer: Option
Explanation:
The
update()
method is used to merge two dictionaries in Python.
7.
What is the purpose of the
dictionary.items()
method?
Answer: Option
Explanation:
The
items()
method returns a list of key-value pairs in the dictionary.
8.
How do you create a dictionary with a default value for all new keys?
Answer: Option
Explanation:
The
defaultdict
from the collections
module is used to create a dictionary with a default value for all new keys.
9.
What is the result of the expression
dictionary.get('key', 'default')
?
Answer: Option
Explanation:
The
get()
method returns the value for 'key' if present, otherwise returns the specified default value.
10.
How do you remove all items from a dictionary?
Answer: Option
Explanation:
The
clear()
method removes all items from a dictionary.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers