To delete a key regardless of whether it is in the dictionary, use the two-argument form of dict.pop():

my_dict.pop('key', None)

This will return my_dict[key] if key exists in the dictionary, and None otherwise. If the second parameter is not specified (i.e. my_dict.pop('key')) and key does not exist, a KeyError is raised.

To delete a key that is guaranteed to exist, you can also use

del my_dict['key']

This will raise a KeyError if the key is not in the dictionary.

Answer from Sven Marnach on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_dictionaries_remove.asp
Python - Remove Dictionary Items
Python Sets Access Set Items Add Set Items Remove Set Items Loop Sets Join Sets Frozenset Set Methods Set Exercises Code Challenge Python Dictionaries
Discussions

Can we have a .delete() for dictionary please
I would like to see a .delete() that doesn’t raise KeyError if the key doesn’t exist. I’m suggesting .delete() so that existing code is not affected. I’m dealing with json input from Grinding Gear Games and i’m getting… More on discuss.python.org
🌐 discuss.python.org
8
0
March 2, 2024
Can we have a .discard() for dictionary please - Ideas - Discussions on Python.org
Ref: https://discuss.python.org/t/can-we-have-a-delete-for-dictionary-please/ In the ref I was given a solution for my problem, which while usable, is not thematically correct. .pop() is for removing and retrieving an existing item (so a .get() and ‘del item’ combined). More on discuss.python.org
🌐 discuss.python.org
1
March 2, 2024
Delete item from dict Python
d = {k:v for k,v in defalutdict.items() if 'UP' not in k} More on reddit.com
🌐 r/learnpython
27
1
July 28, 2021
Python - How to delete an item/value from a key in a dictionary?
If you want to remove the value but keep the key, set the value for the key to something like 'None' More on reddit.com
🌐 r/learnprogramming
9
2
November 13, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-remove-a-key-from-dictionary
Python - Ways to remove a key from dictionary - GeeksforGeeks
October 29, 2025 - If we want to remove the last key-value pair in the dictionary, popitem() is a quick way to do it. Useful for LIFO operations. ... Explanation: popitem() method removes the last inserted key-value pair from the dictionary.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-multiple-keys-from-dictionary
Python - Remove Multiple Keys from Dictionary - GeeksforGeeks
July 12, 2025 - We can use the pop() method to remove keys from the dictionary one by one in a loop.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › python-remove-key-from-dictionary
Python Remove Key from Dictionary – How to Delete Keys from a Dict
February 22, 2023 - We'll discover how to accomplish this using the del keyword, the pop() method, and the popitem() method. Finally, you'll see how to use Python to remove multiple keys from a dictionary.
🌐
Python Morsels
pythonmorsels.com › removing-a-dictionary-key
Removing a dictionary key - Python Morsels
January 13, 2023 - To delete a key from a dictionary, you can use Python's del statement or you can use the dictionary pop method.
🌐
Medium
medium.com › @python-javascript-php-html-css › efficiently-removing-keys-from-python-dictionaries-5edc9a4ab9b3
Remove Keys from Python Dictionaries Effectively
August 24, 2024 - The most efficient method depends on the specific use case, but dictionary.pop(key, None) is generally a concise and safe option for single key removal. ... Removing keys from a Python dictionary safely and efficiently can be achieved through various methods.
🌐
Python Engineer
python-engineer.com › posts › delete-key-dictionary
How to delete a key from a dictionary in Python - Python Engineer
If key is in the dictionary, it removes it and returns its value, else it returns default. If default is not given and the key is not in the dictionary, a KeyError is raised.
🌐
Python.org
discuss.python.org › python help
Can we have a .delete() for dictionary please - Python Help - Discussions on Python.org
March 2, 2024 - I would like to see a .delete() that doesn’t raise KeyError if the key doesn’t exist. I’m suggesting .delete() so that existing code is not affected. I’m dealing with json input from Grinding Gear Games and i’m getting really sick of this: if gem.get("baseTypeName"): del gem["baseTypeName"] if gem["grantedEffect"].get("baseTypeName"): del gem["grantedEffect"]["baseTypeName"] if gem["secondaryGrantedEffect"].get("baseTypeName"): del gem["secondaryGrantedEffe...
🌐
Scaler
scaler.com › home › topics › remove key from dictionary python
remove key from dictionary python | Scaler Topics
May 4, 2023 - We can use the items() method with a for-loop to remove a key from dictionary in Python. We simply iterate over our current dictionary and copy all key-value pairs (except the key to be deleted) to our new dictionary.
🌐
Python.org
discuss.python.org › ideas
Can we have a .discard() for dictionary please - Ideas - Discussions on Python.org
March 2, 2024 - Ref: https://discuss.python.org/t/can-we-have-a-delete-for-dictionary-please/ In the ref I was given a solution for my problem, which while usable, is not thematically correct. .pop() is for removing and retrieving an existing item (so a .get() and ‘del item’ combined).
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › remove multiple keys from python dictionary
Remove Multiple keys from Python Dictionary - Spark By {Examples}
May 31, 2024 - How to remove multiple keys from Python Dictionary? To remove multiple keys you have to create a list or set with the keys you want to delete from a
🌐
Educative
educative.io › answers › how-to-remove-items-from-a-dictionary-in-python
How to remove items from a dictionary in Python
The del keyword method uses the keyword from the dictionary to remove an item. ... The clear() method clears all the items in the dictionary.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-key-from-dictionary-list
Remove Key from Dictionary List - Python - GeeksforGeeks
July 12, 2025 - Explanation: Each dictionary in the list is checked for the key and if it exists then the del statement removes the key-value pair. We use the pop() method to remove the key from each dictionary in the list and if the key does not exist then ...
🌐
Stack Abuse
stackabuse.com › python-how-to-remove-a-key-from-a-dictionary
Python: How to Remove a Key from a Dictionary
September 19, 2021 - The pop(key, d) function removes a key from a dictionary and returns its value. It takes two arguments, the key is removed and the optional value to return if the key isn't found.
🌐
Jinja
jinja.palletsprojects.com › en › stable › templates
Template Designer Documentation — Jinja Documentation (3.1.x)
A dict in Python is a structure that combines keys and values. Keys must be unique and always have exactly one value.
🌐
Google
developers.google.com › google for education › python › python dict and file
Python Dict and File | Python Education | Google for Developers
The "del" operator can remove variables, list elements, or entries from a dictionary. The open() function is used to open files for reading ('r'), writing ('w'), or appending ('a'), with iterating through the file handle being an efficient way ...