KnowledgeBoat Logo
|

Computer Science

Which of the following will raise an error if the given key is not found in the dictionary ?

  1. del statement
  2. pop( )
  3. popitem()
  4. all of these

Python Dictionaries

1 Like

Answer

del statement

Reason — For example:

d = {'list': 'mutable', 'tuple': 'immutable'} 
del d['dictionary']
Output

<module> KeyError: 'dictionary'

Since key named "dictionary" does not exist in d, del keyword will raise an error.

Answered By

1 Like


Related Questions