CBSE Class 11 Computer Science Question 72 of 112

Dictionaries — Question 12

Back to all questions
12
Question

Question 12

How is pop( ) different from popitem( ) ?

Answer

The differences between pop( ) and popitem( ) are mentioned below:

pop( )popitem( )
pop( ) removes the item with the specified key name.popitem( ) removes the last inserted item from the dictionary.
With pop( ), we can specify a return value or a message if the given key is not found in the dictionary.With popitem( ), we cannot specify any such message/return value while deleting from an empty dictionary. It will raise an error in this case.