Open In App

How to Remove All Items From a List in Python

Last Updated : 27 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Removing all items from the list can be done by using various different methods in Python.

Using clear()

clear() method is the simplest and most efficient way to remove all items from a list.

Python
a = [1, 2, 3, 4, 5]

# Remove all items using clear()
a.clear()

# Print the empty list
print(a)

Output
[]

Let's look into the other methods that are used to remove all items from the lists.

Using del(Slice[:])

Another way to remove all items is by using the del() keyword. This removes everything from the list in place.

Python
a = [1, 2, 3, 4, 5]

# Remove all items using del
del a[:]
print(a)

Output
[]

Reassigning to an Empty List

This method creates a new empty list and makes the original variable point to it. This approach is efficient to clear other elements from the list.

Python
a = [1, 2, 3, 4, 5]

# Reassign to an empty list
a = []
print(a)

Output
[]

Using Multiplication with Zero(* 0)

By multiplying a list by 0 will help to modify the list in place. It will create a new list and does not modify the original list.

Python
a = [1, 2, 3, 4, 5]

# Using (*= 0) to clear the list
a *= 0
print(a)

Output
[]

Next Article

Similar Reads