Question #871

What is the output of the code snippet below?
my_dict = {"a": 1, "b": 2}
if "c" not in my_dict:
    my_dict["c"] = 4
if "b" not in my_dict:
    my_dict["c"] = 4
print(my_dict)

As "b" is already a key of my_dict , only the pair "c": 4 is added. (stackoverflow.com/questions/42315072/python-update-a-key-...)


Comment on Disqus:

Question difficulty: ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต