Python Programming - Dictionaries
Exercise : Dictionaries - General Questions
- Dictionaries - General Questions
41.
What is the purpose of the
dictionary.update(key=value)
method?
Answer: Option
Explanation:
The
update()
method with key=value adds a new key-value pair to the dictionary.
42.
How do you remove a specific key-value pair from a dictionary?
Answer: Option
Explanation:
The
del
keyword is used to remove a specific key-value pair from a dictionary.
43.
What is the difference between the
dictionary.keys()
and dictionary.values()
methods?
Answer: Option
Explanation:
The
keys()
method returns a list of keys, and the values()
method returns a list of values in a dictionary.
44.
How do you check if a key exists in a dictionary using the
get()
method?
Answer: Option
Explanation:
The
get()
method returns None
if the key is not present, so checking for is not None
verifies key existence.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers