Does the dictionary pop() function remove the item from the dictionary?



Does the pop() function on a dictionary just access the data or remove it?


The pop() function will return the value for the key AND then remove the key/value from the dictionary. The following code example shows the results of performing a pop() on a dictionary to remove the item indexed by key “C”.

letters = { "A": 10, "B": 20, "C": 30, "D": 40 }

value = letters.pop("C")

# {'A': 10, 'B': 20, 'D': 40}