• d.pop(key) -- consider using this if you need the value for the item being deleted, and/or you want to specify a default value and don't want an exception raised if the key doesn't exist.
    e.g., value = d.pop(key, None)
  • del key -- consider using this if you are certain that the key exists (or you expect an exception if it doesn't), and you don't need the value of the item being deleted.
    e.g., del key

From the official Python language documentation:

del d[key] Remove d[key] from d. Raises a KeyError if key is not in the map.

pop(key[, default]) If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.

https://docs.python.org/3/library/stdtypes.html#mapping-types-dict

Answer from Wang Dingwei on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › difference between "del" and "pop" for removing items from a dictionary.
r/learnpython on Reddit: Difference between "del" and "pop" for removing items from a dictionary.
February 18, 2019 -

I have a dictionary and I wanted to remove one item and documentation mentioned that I can use:

phonebook = {

"John" : 938477566,

"Jack" : 938377264,

"Jill" : 947662781

}

del phonebook["John"]

print(phonebook)

or

phonebook = {

"John" : 938477566,

"Jack" : 938377264,

"Jill" : 947662781

}

phonebook.pop("John")

print(phonebook)

What's the difference between those two?

🌐
Sololearn
sololearn.com › en › Discuss › 1721908 › whats-that-difference-between-pop-and-del-keyword-in-python-dictionaries
What's that difference between pop() and del keyword in ...
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
IT trip
en.ittrip.xyz › python
The Essential Guide to Removing Elements from Dictionaries in Python: del vs. pop | IT trip
November 3, 2023 - The `pop` method, on the other hand, is specific to dictionaries and also allows you to remove and return an element from a dictionary. [h3]Using the del Statement[/h3] The `del` statement is straightforward to use. The basic syntax is as follows: ... It’s important to note that if the key is not found, a `KeyError` is raised. [h4]Example of del in Action[/h4] Consider the following example where we have a dictionary of fruits and their corresponding quantities:
🌐
Javatpoint
javatpoint.com › difference-between-del-and-pop-in-python
Difference between 'del' and 'pop' in python - Javatpoint
Difference between 'del' and 'pop' in python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
🌐
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 - First, the pop() method returns the value of the key removed from a dictionary whereas del does not return any value.
🌐
DataCamp
datacamp.com › tutorial › python-pop
How to Use the Python pop() Method | DataCamp
July 31, 2024 - The del keyword can also be used to remove specified key-value pairs from dictionaries. You should note that using the del keyword does not return the removed element, unlike using the pop() method. The examples below show how to use the del keyword to remove elements from a list and dictionary.
🌐
W3Schools
w3schools.com › python › ref_dictionary_pop.asp
Python Dictionary pop() Method
The value of the removed item is ... item is the return value of the pop() method: car = { "brand": "Ford", "model": "Mustang", "year": 1964 } x = car.pop("model") print(x) Try it Yourself » · Tutorial: Python Dictionary ...
Find elsewhere
Top answer
1 of 3
19
Good question! A simple difference is pop() returns the item removed so it can be assigned a different label while del simply removes the item. If you use pop() and do not assign a new label to the returned object it is essentially performing the same function as del. The list of book title strings is actually a list of references that point to string objects stored in memory. Each string object "id" is the address in memory of the stored object. ```python b1 = "book title 1" b2 = "book title 2" b3 = "book title 3" b4 = "book title 4" book_list = [b1, b2, b3, b4] print(book_list) ['book title 1', 'book title 2', 'book title 3', 'book title 4'] print([id(b1), id(b2), id(b3, id(b4)]) [139996358750368, 139996358750256, 139996358750592, 139996358750648] print([id(book) for book in book_list]) [139996358750368, 139996358750256, 139996358750592, 139996358750648] saved = book_list.pop(0) print(saved) book title 1 print(id(saved)) 139996358750368 ``` In a more detailed look, pop() returns the "id" reference removed so that it can be assigned to another label or used in a subsequent statement. The label saved is assigned to the first book popped from the book list. So, use pop() when you want to have access to the removed item for another purpose, and use del when you no longer want the item. Edit: to comment on “garbage collection”. Garbage collection happens when an object is removed from memory and the memory freed for other uses. This occurs when all references to an object are removed. pop() removed the list’s reference to object (count goes down by 1). If count is now zero, object maybe garbage collected. If a label is assigned to the popped object, this adds a new reference (count goes up by 1). So labeling a pop becomes a wash (no net change in reference count). del removes the label (the count goes down by 1) but not the object. Using del b4 simply removes the label b4 but not the object referenced by b4 since the string “book title 4” is still referenced by the list. Post back if you have more questions. Good luck!!
2 of 3
1
Really good questions and answers. Thank you so much!
🌐
Finxter
blog.finxter.com › home › learn python blog › python dictionary pop() method
Python Dictionary pop() Method - Be on the Right Side of Change
November 23, 2021 - If the specified key exists in the dictionary, dict.pop() returns the value grouped to the deleted (key-value) pair element. If the key doesn’t exist, dict.pop()returns the specified default value. If the key is not present in the dictionary and the default value is not specified, dict.pop()returns a KeyError. An example of a simple Python dict.pop() method operation applied to a Python Dictionary:
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.7 documentation
Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. It raises an IndexError if the list is empty or the index is outside the list range.
🌐
GeeksforGeeks
geeksforgeeks.org › python › what-is-difference-between-del-remove-and-pop-on-python-lists
Difference Between Del, Remove and Pop in Python Lists - GeeksforGeeks
July 23, 2025 - #Remove elements by index a = [1, ... the value we want to remove from list as its argument. ... pop() method removes and returns an element from the list....
🌐
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 - d = {'k1': 1, 'k2': 2} k, v = d.popitem() print(k) print(v) print(d) # k2 # 2 # {'k1': 1} k, v = d.popitem() print(k) print(v) print(d) # k1 # 1 # {} # k, v = d.popitem() # KeyError: 'popitem(): dictionary is empty' ... The clear() method removes all items from a dictionary, making it empty. Built-in Types - dict.clear() — Python 3.13.3 documentation · d = {'k1': 1, 'k2': 2, 'k3': 3} d.clear() print(d) # {} ... The del statement can also be used to delete an item from a dictionary.
🌐
Medium
allwin-raju.medium.com › understanding-pop-remove-and-del-in-python-abb9e0223706
Understanding pop, remove, and del in Python | by Allwin Raju | Medium
December 1, 2024 - Raises an error if the index (list) or key (dictionary) doesn’t exist. If you’re working with lists, pop() can remove an element at a specific position (default is the last element). # Removing the last element lst = [10, 20, 30, 40] last_item = lst.pop() # Removes 40 print(lst) # Output: [10, 20, 30] print(last_item) # Output: 40 # Removing an element at a…
🌐
Python Guides
pythonguides.com › python-dictionary-pop
Free Python & Machine Learning Tutorials for All Levels - Python Guides
June 29, 2026 - Practical, beginner-friendly tutorials on Python, machine learning, Django, React, and more.
🌐
Pythontutor
pythontutor.net › home › python tutorial › python dictionaries › dictionary methods › pop() method
Python Dictionary pop() Method with Examples – Remove Dictionary Elements
If the key is missing and no default ... removed from the dictionary, along with its value. Unlike the del keyword, pop() gives you access to the value it deleted, so you can store or use it right away....
🌐
STechies
stechies.com › difference-between-del-remove-pop-lists
Difference between del, remove and pop Methods in Python
In the above example, we first ... the list element, we printed the updated list. Python pop() function is used to return the removed element from the given list....
🌐
SitePoint
sitepoint.com › python hub › remove dictionary items
Python - Remove Dictionary Items | SitePoint — SitePoint
Remember that removing items from a dictionary is an immediate operation - once removed, the key-value pair is gone unless you've stored it elsewhere. If you try to remove a non-existent key using del, Python will raise a KeyError. However, if you use pop() with a default value (dict.pop('key', default_value)), it will return the default value instead of raising an error.