# random sales dictionary
sales = { 'apple': 2, 'orange': 3, 'grapes': 4 }
element = sales.pop('apple')
print('The popped element is:', element)
print('The dictionary is:', sales)
Output
The popped element is: 2
The dictionary is: {'orange': 3, 'grapes': 4}
Syntax of Dictionary pop()
The syntax of pop() method is
dictionary.pop(key[, default])
pop() method takes two parameters:
The pop() method returns:
If key is found - removed/popped element from the dictionary
If key is not found - value specified as the second argument (default)
If key is not found and default argument is not specified - KeyError exception is raised
출처: https://www.programiz.com/python-programming/methods/dictionary/pop