Q. Suppose

>>>d1 = {1: 'one', 2: 'two', 3: 'three', 4: 'four'}

>>>d2 = {5: 'five', 6: 'six'}


Write the output of the following code:


(a)

>>>d1.items ()

>>>d1.keys ()

>>>d1.values ()

>>>d1.update (d2)

>>>len (d1)


(b)

>>>del d1[3]

>>>print (d1)

>>>d1.pop (4)

>>>print (d1)

>>>d1 [8] = 'eight'

>>>print (d1)

>>>d1.clear ()

>>>print (d1)


Answer :-


(a)


>>> d1.items ()

dict_items([(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')])

>>> d1.keys ()

dict_keys([1, 2, 3, 4])

>>> d1.values ()

dict_values(['one', 'two', 'three', 'four'])

>>> d1.update (d2)

>>> len (d1)

6

>>>


(b)


>>> del d1[3]

>>> print (d1)

{1: 'one', 2: 'two', 4: 'four', 5: 'five', 6: 'six'}

>>> d1.pop (4)

'four'

>>> print (d1)

{1: 'one', 2: 'two', 5: 'five', 6: 'six'}

>>> d1 [8] = 'eight'

>>> print (d1)

{1: 'one', 2: 'two', 5: 'five', 6: 'six', 8: 'eight'}

>>> d1.clear ()

>>> print (d1)

{}

>>>


Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post