Python Programming - Dictionaries
Exercise : Dictionaries - General Questions
- Dictionaries - General Questions
31.
What is the purpose of the
dictionary.popitem()
method?
Answer: Option
Explanation:
The
popitem()
method removes a random key-value pair from the dictionary.
32.
How do you merge two dictionaries?
Answer: Option
Explanation:
The
update()
method is used to merge two dictionaries in Python.
33.
How do you create a dictionary with default values for keys?
Answer: Option
Explanation:
The
fromkeys()
method is used to create a dictionary with default values for specified keys.
34.
How do you check if a key exists in a dictionary without raising an error if the key is not present?
Answer: Option
Explanation:
The
in
keyword is used to check if a key exists in a dictionary.
35.
How do you extract all values from a dictionary and store them in a list?
Answer: Option
Explanation:
The
values()
method is used to extract all values from a dictionary, and list()
is used to convert it into a list.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers