Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteTo remove a dictionary entry by its key, use del my_dict[key]. If you also need the removed value, use my_dict.pop(key). Both raise KeyError when the key is missing; pop can instead return a fallback if you provide one.
Remove an entry by key
A dictionary entry consists of a key and its associated value. Python removes the entry by key—not by searching for its value. Use del when you only need to delete the entry:
person = {"name": "Ada", "age": 36}
del person["age"]
print(person) # {'name': 'Ada'}
del person["age"] changes the existing dictionary in place. It raises KeyError if "age" is not a key in the dictionary.
Choose the removal method you need
| Need | Operation | What happens |
|---|---|---|
| Delete a known key without using its value | del d[key] |
Removes the entry; raises KeyError if the key is absent. |
| Delete a key and retrieve its value | d.pop(key) |
Removes and returns the value; raises KeyError if the key is absent. |
| Delete a key only if present | d.pop(key, default) |
Removes and returns the value if present; otherwise returns default. |
| Remove the most recently inserted entry | d.popitem() |
Removes and returns a (key, value) pair; raises KeyError if the dictionary is empty. |
| Remove every entry | d.clear() |
Empties the dictionary. |
These operations and their behavior are documented in the Python 3.14.8 built-in types reference.
#1 Best Overall
Use pop when you need the removed value
pop removes the entry and returns its value, which is useful when the value should be saved or used immediately:
person = {"name": "Ada", "age": 36}
name = person.pop("name")
print(name) # Ada
print(person) # {'age': 36}
To avoid an error when a key may be absent, pass a default:
Rank #2
age = person.pop("age", None)
If "age" is missing, this returns None without changing the dictionary. Use this form only when None is an acceptable fallback. If None could also be a stored value and you need to tell that apart from a missing key, use a unique sentinel:
missing = object()
value = person.pop("age", missing)
if value is missing:
print("No age entry")
Remove the latest entry or empty the dictionary
Remove the most recently inserted pair
Call popitem() when you want to remove and receive the most recently inserted key-value pair:
last_key, last_value = person.popitem()
Dictionaries preserve insertion order, and popitem() removes pairs in last-in, first-out order in current Python; that order has been guaranteed since Python 3.7. Calling it on an empty dictionary raises KeyError.
Remove all entries
Call clear() to empty the dictionary in place:
person.clear()
Afterward, the dictionary still exists, but it contains no entries.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Removing an entry by its value
del and pop take a key, not a value. Python dictionaries do not provide a remove(value) method. If your goal is to exclude entries with a particular value, build a new dictionary by filtering its items:
scores = {"Ada": 10, "Lin": 7, "Sam": 10}
without_tens = {
key: value
for key, value in scores.items()
if value != 10
}
print(without_tens) # {'Lin': 7}
This creates a new dictionary and leaves scores unchanged. The dictionary removal operations are described in the official Python documentation.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




