Python Programming - Data Types - Discussion
Discussion Forum : Data Types - General Questions (Q.No. 64)
64.
What will be the result of the following code snippet?
my_dict = {'a': 1, 'b': 2, 'c': 3}
result = my_dict.keys()
print(result)
Answer: Option
Explanation:
The keys()
method in Python returns a view object that displays a list of all the keys in the dictionary.
In this case, it will return a view object containing the keys 'a'
, 'b'
, and 'c'
. When printed, it shows as dict_keys(['a', 'b', 'c'])
. This is a view object, not a list, but it behaves similarly in many situations.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers