Computer Science, asked by mehwishh, 3 months ago

17)
Give the output of the following code
d = {1:"X', 2:'Y', 3:"Z"}
del d[1]
print(d.keys())
d[1] = 'D'
print(d)
del d[2]
print(len(d))
y={4:'D',5:'E')
d.update(y)
print(d)

Answers

Answered by Equestriadash
8

Given dictionary:

d = {1:'X', 2:'Y', 3:'Z'}

>>> del d[1]

#deletes the element in the dictionary with the key as '1', i.e., 1:'X' gets deleted.

>>> print(d.keys())

#returns the keys in the dictionary in the form of a list.

  • dict_keys([2, 3])

>>> del d[2]

#deletes the element in the dictionary with the key as '2', i.e., 2:'Y' gets deleted.

>>> print(len(d))

#returns the length of the dictionary.

  • 1

>>> y = {4:'D', 5:'E'}

#another dictionary is created.

>>> d.update(y)

#dictionary 'y' gets appended into dictionary 'd'.

>>> print(d)

#returns dictionary 'd'.

  • {3: 'Z', 4: 'D', 5: 'E'}
Similar questions