CBSE Class 11 Computer Science Question 29 of 112

Dictionaries — Question 9

Back to all questions
9
Question

Question 9

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
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.