Create a dictionary named with three entries, for key ‘a’, ‘b’ and ‘c’.
What happened if you try to index a nonexistent key (D[‘d’]) ?
What does python do if you try to assign to a nonexistent key d.
e.g. D[‘d’]=‘spam’

if we try to index a nonexistent key (D[‘d’])  than it will produce ‘keyerror’.

if we try to assign to a nonexistent key d than it will add a new element in dictionary.

error: Content is protected !!