Python Programming - Dictionaries
Exercise : Dictionaries - General Questions
- Dictionaries - General Questions
16.
What does the
dictionary.fromkeys(keys, default_value)
method do?
Answer: Option
Explanation:
The
fromkeys()
method creates a new dictionary with specified keys and default values.
17.
What is the purpose of the
dictionary.reverse()
method?
Answer: Option
Explanation:
Unlike lists, dictionaries do not have a
reverse()
method.
18.
How do you merge two dictionaries and create a new one?
Answer: Option
Explanation:
Using the syntax
{**dict, **another_dict}
allows you to merge two dictionaries and create a new one.
19.
How do you check if a key exists in a dictionary without raising an error?
Answer: Option
Explanation:
The
in
keyword is used to check if a key exists in a dictionary without raising an error.
20.
What does the
dictionary.pop(key, default_value)
method do?
Answer: Option
Explanation:
The
pop()
method returns the value for the key or the default value if the key is not present and removes the key from the dictionary.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers