Python Programming - Variables - Discussion

Discussion Forum : Variables - General Questions (Q.No. 25)
25.
What is the output of the following code:
my_dict = {'a': 1, 'b': 2, 'c': 3}
del my_dict['b']
print(my_dict)
{'a': 1}
{'a': 1, 'c': 3}
{'a': 1, 'b': 2, 'c': 3}
An error is raised
Answer: Option
Explanation:

In this code, a dictionary my_dict is defined with three key-value pairs.

The second line uses the del statement to remove the key-value pair with the key 'b' from the dictionary.

When the dictionary is printed to the console, it shows the modified dictionary {'a': 1, 'c': 3}.

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.