Python Programming - Dictionaries
Exercise : Dictionaries - General Questions
- Dictionaries - General Questions
21.
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.
22.
What is the result of the expression
len(dictionary.values())
?
Answer: Option
Explanation:
The
len()
function returns the number of values in a dictionary.
23.
How do you remove a key-value pair from a dictionary in Python without raising an error if the key is not present?
Answer: Option
Explanation:
The
pop()
method with a default value of None
removes a key-value pair from a dictionary without raising an error if the key is not present.
24.
How do you create an empty dictionary?
Answer: Option
Explanation:
An empty dictionary in Python can be created using curly braces
{}
.
25.
What is the purpose of the
dictionary.update(another_dict)
method?
Answer: Option
Explanation:
The
update()
method merges two dictionaries, updating values for common keys.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers