10
Question Question 10
Which of the following will raise an error if the given dictionary is empty ?
- del statement
- pop( )
- popitem( )
- all of these
popitem()
Reason — Calling popitem() method on an empty dictionary will throw a KeyError.
For example:
d = {}
d.popitem()Output
KeyError: 'popitem(): dictionary is empty'