Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Remove List Items

Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Remove List Items

Python Remove Items from a List

Once a list is created, you might want to remove something from it — maybe the last item, a specific item, or even clear everything. Python offers different ways to handle all of that smoothly.

Let’s look at the methods to remove items from a list.

pop() – Remove by Index or Remove Last

The pop() method removes elements using their index. If you don’t pass any index, it removes the last item by default.

Example: Remove the last item
				
					fruits = ["Apple", "Banana", "Cherry", "Mango"]
fruits.pop()
print(fruits)

				
			

Output:

				
					['Apple', 'Banana', 'Cherry']

				
			
Example: Remove a specific index
				
					fruits = ["Apple", "Banana", "Cherry", "Mango"]
fruits.pop(1)
print(fruits)

				
			

Output:

				
					['Apple', 'Cherry', 'Mango']

				
			

remove() – Delete by Value

If you don’t care about indexes and just want to remove a specific value, use remove().

				
					colors = ["Pink", "Cyan", "Blue", "Cyan", "Purple"]
colors.remove("Cyan")
print(colors)

				
			

Output:

				
					['Pink', 'Blue', 'Cyan', 'Purple']

				
			

Note: It removes only the first match.

del – Remove by Index or Delete Entire List

The del keyword can:

  • delete an item at a specific index

  • delete a range of items

  • or delete the list entirely

Example: Delete one item
				
					cities = ["Lahore", "Karachi", "Islamabad", "Multan"]
del cities[2]
print(cities)

				
			

Output:

				
					['Lahore', 'Karachi', 'Multan']

				
			
Example: Delete the entire list
				
					students = ["Ali", "Zara", "Hamza"]
del students
print(students)

				
			

Output:

				
					NameError: name 'students' is not defined

				
			

Once deleted, the list variable doesn’t exist anymore.

clear() – Empty the List, Keep the Variable

If you want to keep the list but remove all its items, use clear().

				
					marks = [89, 74, 91, 65]
marks.clear()
print(marks)

				
			

Output:

				
					[]

				
			

This gives you an empty list that you can reuse later.

Summary

MethodRemoves…
pop()Item at given index or last one
remove()First occurrence of given value
delIndex, slice, or whole list
clear()All items, keeps empty list
Scroll to Top