Python Programming - Variables - Discussion

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

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

The second line adds a new key "c" with the value 3 to the dictionary.

When the modified dictionary is printed to the console, the output is {"a": 1, "b": 2, "c": 3}.

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

Post your comments here:

Your comments will be displayed after verification.