Different ways to Clear a List in Python (original) (raw)

Last Updated : 26 Nov, 2025

Given a list, the task is to remove all elements from it. **For Example:

**Input: [10, 20, 30, 40]
**Output: []

Let's explore diiferent methods to clear a list in Python.

Using clear() Method

clear() empties the list directly by removing all elements from the same list object.

Python `

a = [1, 2, 3, 4, 5] a.clear() print(a)

`

**Explanation:

Using del a[:]

del a[:] deletes every element inside the list using slicing while keeping the same list reference.

Python `

a = [1, 2, 3, 4, 5] del a[:] print(a)

`

**Explanation:

Using a Loop with pop()

This method removes elements one by one until the list becomes empty using pop(). It works but is the slowest option.

Python `

a = [1, 2, 3, 4, 5] while a: a.pop() print(a)

`

**Explanation:

Reassigning to []

Assigning the name to a new empty list does not modify the old list, it simply makes the variable point to a fresh empty list.

Python `

a = [1, 2, 3, 4, 5] a = [] print(a)

`

**Explanation:

**Note: Using a = [] does not clear the original list - it only reassigns the variable to a new empty list. If other variables reference the same list, they will still hold the old data.