Python Programming - Dictionaries
Exercise : Dictionaries - General Questions
- Dictionaries - General Questions
1.
How do you check if a key is present in a dictionary?
Answer: Option
Explanation:
The
in
keyword is used to check if a key is present in a dictionary.
2.
How do you retrieve all keys from a dictionary?
Answer: Option
Explanation:
The
keys()
method is used to retrieve all keys from a dictionary.
3.
What is the purpose of the
dictionary.setdefault(key, default_value)
method?
Answer: Option
Explanation:
The
setdefault()
method sets the default value for a key if the key is not present in the dictionary.
4.
How do you remove a key-value pair from a dictionary?
Answer: Option
Explanation:
The
pop()
method is used to remove a key-value pair from a dictionary.
5.
What is the result of the expression
len(dictionary)
?
Answer: Option
Explanation:
The
len()
function returns the number of keys in a dictionary.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers