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
🌐
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.
Discussions

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
Removing key value pairs from a dictionary
Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you. I think I have detected some formatting issues with your submission: Python code found in submission text that's not formatted as code. If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting. Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here . More on reddit.com
🌐 r/learnpython
10
1
October 14, 2022
How can I remove keys in a dictionary where the value is empty?
Create a new dictionary: myDict = {key: value for key, value in myDict if value} More on reddit.com
🌐 r/learnpython
14
18
February 25, 2021
Is there a way to remove items/keys from a dict in a loop?
d = { ... } for k in list(d.keys()): d.pop(k, None) The important bit is the list(d.keys(). Instead of iterating over the dict itself, that creates a new separate list of keys and iterates over that. More on reddit.com
🌐 r/learnpython
59
81
May 27, 2022
🌐
Note.nkmk.me
note.nkmk.me › home › python
Remove an Item from a Dictionary in Python: pop, popitem, clear, del | note.nkmk.me
April 27, 2025 - In Python, you can remove an item (key-value pair) from a dictionary (dict) using the pop(), popitem(), clear() methods, or the del statement. You can also remove items based on specific conditions us ...
🌐
Educative
educative.io › answers › how-to-remove-a-key-value-pair-from-a-dictionary-in-python
How to remove a key value pair from a dictionary in Python
We can remove multiple keys from a dictionary using the pop() method. We can delete all Keys from a Dictionary using the del keyword. The del keyword deletes a key-value pair from a dictionary.
🌐
W3Schools
w3schools.com › python › python_dictionaries_remove.asp
Python - Remove Dictionary Items
Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercises Code Challenge Python If...Else
🌐
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.
🌐
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.
Find elsewhere
🌐
Board Infinity
boardinfinity.com › blog › how-to-remove-key-from-python-dictionary
Remove key from python dictionary | Board Infinity
January 2, 2025 - Let's explore them in depth. The del statement is the easiest method to eradicate a key from a dictionary. ... • If the key does not exist, this particular method will return a KeyError.
🌐
Scaler
scaler.com › home › topics › remove key from dictionary python
remove key from dictionary python | Scaler Topics
May 4, 2023 - You can remove key from dictionary in Python using the pop() method on a dictionary object, say dict. It removes the specified key (and associated value) from the dictionary and returns the value associated with the key.
🌐
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 - This can be done with the pop() function, the del keyword, and with dict comprehensions. 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.
🌐
Python Engineer
python-engineer.com › posts › delete-key-dictionary
How to delete a key from a dictionary in Python - Python Engineer
This article shows how you can remove a key from a dictionary in Python. ... The second option is to use the pop(key[, default]) method. If key is in the dictionary, it removes it and returns its value, else it returns default.
🌐
Career Karma
careerkarma.com › blog › python › python remove key from a dictionary: a complete guide
Python Remove Key from a Dictionary: A Complete Guide: A Complete Guide | Career Karma
December 1, 2023 - The Python pop() method and del keyword remove keys from a dictionary. pop() accepts the name of the key you want to remove from the dictionary as an argument. The del keyword stands on its own and refers to a specific key.
🌐
Medium
medium.com › @python-javascript-php-html-css › efficiently-removing-keys-from-python-dictionaries-5edc9a4ab9b3
Remove Keys from Python Dictionaries Effectively
August 24, 2024 - Another alternative is using the dict.popitem() method, which removes and returns an arbitrary (key, value) pair from the dictionary. This method can be useful in certain scenarios where you need to repeatedly remove and process items from the ...
🌐
Pierian Training
pieriantraining.com › home › how to remove key from python dictionary
How to remove key from Python Dictionary - Pierian Training
May 19, 2023 - This code checks if `’banana’` is in `my_dict`, and only deletes it if it exists in the dictionary. In conclusion, removing a key-value pair from a Python dictionary is easy using the `del` keyword.
🌐
Vultr Docs
docs.vultr.com › python › standard-library › dict › pop
Python dict pop() - Remove Key-Value Pair | Vultr Docs
November 7, 2024 - Start with a dictionary containing some key-value pairs. Choose a key to remove and use the pop() method. ... person = {'name': 'John', 'age': 30, 'city': 'New York'} age = person.pop('age') print(person) print("Removed age:", age) Explain Code ...
🌐
datagy
datagy.io › home › python posts › python: remove key from dictionary (4 different ways)
Python: Remove Key from Dictionary (4 Different Ways) • datagy
December 20, 2022 - The Python .pop() method is a very useful method that allows us to get a dictionary item and remove its key from the dictionary. ... The first parameter is the key we want to remove and the second (optional) parameter is the value that should ...
🌐
Codefinity
codefinity.com › courses › v2 › 102a5c09-d0fd-4d74-b116-a7f25cb8d9fe › 972d480a-794b-4a56-9980-e8fa636afef4 › d058c2f1-cc32-4dd6-b6e6-b219eab15346
Learn Removing Dictionary Entries | Mastering Python Dictionaries
In Python, you can remove keys from a dictionary using the del keyword. This allows you to delete specific entries or even clear the entire dictionary. Let's explore how this works using a library-related example. del dict[key] 123456789101112 ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-item-from-dictionary-by-value
Python Remove Item from Dictionary by Value - GeeksforGeeks
July 23, 2025 - Explanation: We iterate over all key-value pairs using d.items() and the condition v != 2 ensures that only items with values not equal to 2 are included in the new dictionary, then the original dictionary is updated with the filtered result. Let's explore some more methods and see how we can remove item from ...
🌐
Better Stack
betterstack.com › community › questions › how-to-delete-dictionary-element-in-python
How to delete an element from a dictionary in Python? | Better Stack Community
To remove a key from a dictionary, you can use the del statement. Here's an example: my_dict = {'a': 1, 'b': 2, 'c': 3} del my_dict['b'] print(my_dict) # Output: {'a': 1, 'c': 3} Alternatively, yo...