Table of contents
1.
Introduction
2.
remove 
3.
pop
4.
del
5.
Difference Between pop and remove in Python and the del Keyword
6.
Frequently Asked Questions
6.1.
What is the difference between pop() and del?
6.2.
How are pop() and remove() similar?
6.3.
What is the return value of pop()?
6.4.
What is the return value of remove()?
6.5.
What if pop() is applied to an empty list?
6.6.
Can I pop() in a tuple like a list?
7.
Conclusion
Last Updated: Aug 12, 2025
Easy

What is the Difference Between del, pop and remove in Python?

Author Vanshika
0 upvote

Introduction

A list is one of the important data structures in Python. It is used to store data collections even of different data types. We perform various operations on Python lists, like adding elements, updating elements, and removing elements. Removing elements is one of the major operations of the list. It can be carried by the del keyword and pop and remove functions. 

Which one should we use? What is this del, and the difference between pop and remove in Python, including the del keyword? 

Don't worry. In this article, you will learn about these in detail.

Difference between del, pop() and remove() in Python

Also See, Divmod in Python, Swapcase in Python

remove 

remove() is an in-built function in Python. As the name suggests, it is used to remove the elements from the lists. It removes the element by value based on its first occurrence. 

It takes the value to be removed as its parameter and checks for that value in the list. If the element is found, it deletes from the list. The first occurring element is deleted if multiple elements have the same value as the parameter. There may be a case when the given value is not present in the list, and it gives an error.

Syntax

list_name.remove(value)
You can also try this code with Online Python Compiler
Run Code


Consider the example below.

# Removal of element using remove()

# Taking input from the user
n = int(input("Enter number of elements : "))

print(f"Enter {n} elements: ")
# Empty list
lst = []

for i in range(0, n):
	# Adding the element
	element = int(input())
	lst.append(element) 
print(lst)

# Deleting 5 if it's there in the list
lst.remove(5)  
print("List after removal:", lst)

# Deleting -4, if it's there in the list
lst.remove(-4)  
print("List after removal: ",lst)
You can also try this code with Online Python Compiler
Run Code


Output

Output of the code using remove

In the code, there is a list ‘lst’. It contains [4,3,2,5,-9], which are inputted by the user. ‘lst.remove(5)’ checks if there is 5 or not in the list. It finds yes, 5 is there; therefore, it deletes it. For ‘lst.remove(-4)’, it gives ValueError, saying ‘x not in list’, which means -4 is not the list. 

It will be crystal clear by the analogy. You go to buy chocolate X. If X is available, you buy it; else, you'll say I didn't get X. Here, X corresponds to the element you need to find from the available chocolates, i.e., from the list of the elements. If you get the element in the list, you delete it (buy X); else, give an error (X not found).

Time complexity is O(n), where n is the size of the list. The element that needs to be deleted from the list can be anywhere. Therefore, a linear scan is done to find the element before it can be removed. On getting the element to be deleted, it further shifts all the elements towards the left.

Also see, Merge Sort Python and Convert String to List Python.

pop

Like, remove(), pop() is also an in-built function used in Python for deleting the elements from the list. It removes the value based on the index. It takes the index/position of the element to be removed as its parameter. Passing the index is optional. If the index is specified, then it removes the element present at that particular position, else removes the last element of the list. The catch is it returns the removed element. 

Syntax

# Index not specified
list_name.pop() 

'''
Or
'''

# Index of the element to be deleted
list_name.pop(index) 
You can also try this code with Online Python Compiler
Run Code


Consider the following example.

# Removal of element using pop()

# Taking input from the user
n = int(input("Enter number of elements : "))
print(f"Enter {n} elements: ")
# Empty list
lst = []

for i in range(0, n):
	# Adding the element
	element = int(input())
	lst.append(element)  

print("List initially:", lst)

# Popping the element at 3rd index
print("Popped element: ",lst.pop(3))    
print("List after popping:", lst)

# Popping the last element
print("Popped element: ", lst.pop()) 
print("List after popping: ", lst)
You can also try this code with Online Python Compiler
Run Code


Output

Output of the code using pop function in Python

In the code, lst is the list containing [2,5,7,0,6] elements inputted by the user. lst.pop(3) pops out the element at index 3, which is 0, and prints the list as [2,5,7,6]. Now, pop() is used without specifying the index as lst.pop(). It deletes the last element from the list and returns the element that popped out as 6.

If popped from the empty list 

lst = []

# If popping from the empty list
print(lst.pop())
You can also try this code with Online Python Compiler
Run Code


Output

Output of the code using pop function in Python

List lst is empty, and it does not contain any element. If the pop() function is applied on this empty list, it gives IndexError saying pop from the empty list. Consider you have ₹0 and your friend asks to give ₹100, then you won't be able to provide and say I don't have money. So, it gives an error.  

If an invalid index is passed

lst = [1,2,3]
print(lst.pop(3))
You can also try this code with Online Python Compiler
Run Code


Output

Output of the code using pop function in Python

List lst contains [1,2,3]. lst.pop(3) gives IndexError with the message pop index out of range because the list does not have any element at index 3. There are 3 elements in total. It is similar to if your friend asks to give ₹100, but you only have ₹50. 

Time complexity is O(1) if the last element of a Python list is to be popped, and it is O(n) if an arbitrary element is to be popped because the rest of the list has to be shifted.

Also see, Python Operator Precedence

del

Like pop() and remove(), del is not a built-in function. It is a keyword. But it also functions in removing elements based on a specific index. It can delete the whole list and slice it, meaning it can remove a part of the list. It takes the index as an argument. If no index is given in the parameter, then it gives IndexError.

Syntax

# For deleting element at specific index
del list_name[index] 

# For deleting the whole list
del list_name 
You can also try this code with Online Python Compiler
Run Code


Consider the following example

# Removal of element using del

# Taking input from the user
n = int(input("Enter number of elements : "))
print(f"Enter {n} elements: ")

# Empty list
lst = [] 

for i in range(0, n):
	# Adding the element
	element = int(input())
	lst.append(element)  
print("Initial list: ", lst)

# Deletion of element of index 2
del lst[3]  
print("List after deletion:", lst)

# Deletion of element at index -1
del lst[-1] 
print("List after deletion: ", lst)

del lst
print("List: ", lst)
You can also try this code with Online Python Compiler
Run Code

 

Output

Output of the code using del keyword in Python

In this code, the list lst is taken input from the user. Initially, the list contains [4,7,0,2,-90,-8]. 

Here, del lst[3] deletes the element at index 3, which is 2. Further, del lst[-1] deletes the element at the index -1 i.e., -8(If it is -1, then we see the 1st index from the right). At last del lst deletes the whole list last. Then, it gives NameError because the compiler is unable to find any list lst as we have already deleted using ‘del lst’. The list got deleted using the del keyword.

Slicing of the list

# Slicing of the list
lst = [2,34,90,'hey', 0.24]
print("List before deletion: ",lst)

del lst[2:]
print("List after deletion: ",lst)
You can also try this code with Online Python Compiler
Run Code


Output

Output of the code of slicing of list using del keyword

In the above code, the list is sliced, which means a part of the list is deleted. List lst contains [2, 34, 90, ’hey’, 0.24]. del lst[2:] slices the list from index 2 to the length of the list. Therefore, we are left with [2, 34], and all the elements are deleted.

Passing the invalid index value

lst = [2,34]
del lst[3]
print(lst)
You can also try this code with Online Python Compiler
Run Code


Output

Output of the code using del keyword

Passing the invalid index gives IndexError, saying, “list assignment index out of range”. The list lst contains only two elements [2,34], del lst[3] is invalid because there is no element at index 3.

Time complexity is O(n), where n is the size of the list. The element to be deleted from the list must be scanned in the whole list.

You can try it on online python compiler.

Must Read Python List Operations

Difference Between pop and remove in Python and the del Keyword

You might have understood the basic difference between pop and remove in Python and the del keyword from the above-explained functions. For more clarity and ease, the following is the difference between pop and remove in Python:

pop()

remove()

del

The pop() function removes the last element or the element based on the index given.remove() function removes the first occurrence of the specified element.The del keyword removes the element specified by the index, deletes the whole list as well as slices the list.
It does not require a parameter; it is optional.It requires a parameter. The value of the element is passed as the parameter.It requires the index value, or else it deletes the whole list.
It returns the value of the deleted element.It does not return any value.It does not return any value.
Syntax: list_name.pop()Syntax: list_name.remove(value)

Syntax: del list_name

or del list_name[index]

Time complexity is O(1) when the last element is to be removed. Otherwise, it is O(n) for extracting an element at the specified index.Time complexity is O(n)Time complexity is O(n).
It gives IndexError if the specified index is not found.It gives ValueError if the specified value is not found.It gives IndexError if the specified index is not found.
It gives no error if the parameter is not passed.It throws TypeError if the parameter is not passed.It does not throw any error if the index is not given. It will delete the complete list.

Ninjas, by this time, you must have understood the difference between pop and remove in Python, how these built-in functions differ from each other and from the del keyword and which function must be used at what time.

You can also read about the Multilevel Inheritance in Python.

Recommended Topic - Difference between argument and parameter

Frequently Asked Questions

What is the difference between pop() and del?

del removes an element(s) by index. At the same time, pop() removes it by index and also returns the value. pop() is a function, and del is a keyword in Python.

How are pop() and remove() similar?

Both pop and remove are the in-built functions in Python which work on lists for deleting elements.

What is the return value of pop()?

The pop() function returns the popped element.

What is the return value of remove()?

It is a void return type function, i.e., it does not return anything.

What if pop() is applied to an empty list?

It will give an IndexError saying pop from an empty list. 

Can I pop() in a tuple like a list?

No, tuples are immutable and don't have a pop method.

Conclusion

In this article, you learned about return and pop - the two built-in functions of Python. You gained in depth knowledge of the difference between pop and remove in Python, how pop(), remove() and del are different from each other and at what time which of the two must be used. The article is based on the building up of your basics in Python. You must have a strong foundation for outshining the future.

Check out this problem - First And Last Occurrences Of X

Read our other related articles:

Live masterclass