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)
{'a', 'b', 'c'}
['a', 'b', 'c']
dict_keys(['a', 'b', 'c'])
Error
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:

Your comments will be displayed after verification.