What will be the output after the following statements?
x= {'year': 2016, 'month': 'March'}
if 'day' not in x
x[day'] = 'Tuesday'
print(x)
(a) ('day', 'Tuesday)
(b) {'day': 'Tuesday', 'month': 'March'}
(c) 'day': 'Tuesday', 'month': 'March',
'year': 2016
(d) {'day': 'Tuesday', 'month': 'March',
'year': 2016
Answers
Answered by
35
Correcting the code a bit to,
The result should be :
which is now of the options but if I had to chose I'll go with (d) with com correction of course as since all the elements are there but the indices are wrong.
Explanation:
dictionary ["key"] = "value" adds a key-value pair in the end of the dictionary.
Answered by
19
The output will be {'year': 2016, 'month': 'March', 'day': 'Tuesday'}
Explanation:
As the key day doesn't exist in dict x, it will create it with the value Tuesday
Similar questions
India Languages,
2 months ago
Science,
2 months ago
Math,
4 months ago
English,
4 months ago
Math,
10 months ago