(ii) print (mon [28])
8. Consider the dictionary 'mon' given below and do as directed:
mon = { 'Jan':31, 'Feb':28, 'Mar':31, 'April':30)
(a) Find the incorrect statement(s) out of the following:
(i) print (mon['Jan']
(b) Write the output of the following code:
mon[ "Feb"] = 29
print (mon)
del mon [ "April"]
print (mon)
mon.clear()
print (mon)
Answers
Answered by
7
Given dictionary:
mon = {'Jan':31, 'Feb':28, 'Mar':31, 'April':30}
(a) Given statements:
- (i) print(mon['Jan'])
- (ii) print(mon [28])
The incorrect statement will be (ii) print(mon[28]) since there is no key by the name '28' in the given dictionary.
(b)
>>> mon["Feb"] = 29
#adds a new key 'Feb' with the value 29 into the dictionary, 'mon'.
>>> print(mon)
{'Jan': 31, 'Feb': 29, 'Mar': 31, 'April': 30}
>>> del mon["April"]
#deletes the key 'April' from the dictionary 'mon'.
>>> print(mon)
{'Jan': 31, 'Feb': 29, 'Mar': 31}
>>> mon.clear()
#clears the elements in the dictionary, making it an empty dictionary.
>>> print(mon)
{}
Similar questions