How to Clear a List in Python

To clear a list in Python, call my_list.clear(). It removes every item from the list in place, so the list object itself survives and is simply empty.

The other options, del my_list[:] and my_list = [], look similar but behave differently when another variable points at the same list.

In this article, I’ll show you each way to empty a list, when it matters which one you pick, and how they compare. I ran every snippet on Python 3.12.5.

The sample list we’ll clear

Every example uses a small shopping cart, plus a second name for the same list:

cart = ["laptop stand", "USB-C hub", "desk lamp"]
checkout = cart          # a second name for the SAME list
  • cart holds three items
  • checkout is not a copy; it points at the very same list

That shared reference is the whole story. If lists being shared by name is new to you, see mutable vs immutable in Python first, or creating an empty list to start from scratch.

Method 1: Clear a list with list.clear() (Recommended)

Here’s the code, using the cart and checkout names from above:

cart = ["laptop stand", "USB-C hub", "desk lamp"]
checkout = cart          # a second name for the SAME list

cart.clear()
print(cart)
print(checkout)
print(cart is checkout)

Output:

[]
[]
True

Both names print an empty list, and cart is checkout stays True.

Command Prompt output of Python list.clear() emptying a shopping cart list, with the second variable also showing an empty list
After cart.clear(), both cart and checkout show an empty list, and they still refer to the same object.

How does this code work?

clear() deletes every item from the existing list object. It doesn’t create anything new and returns None.

Because checkout points at that same object, it sees the empty list too. This is the behavior you want when other code holds a reference, such as a list that you also pop from elsewhere.

Method 2: Clear a list with del and slice assignment

Before Python 3.3 there was no clear(), so people wrote del my_list[:]. It still works.

Let me show you both forms:

cart = ["laptop stand", "USB-C hub", "desk lamp"]
checkout = cart          # a second name for the SAME list

del cart[:]
print(cart, checkout)

cart.extend(["monitor", "webcam"])
cart[:] = []             # slice assignment does the same job
print(cart, checkout)

Output:

[] []
[] []
Command Prompt output of Python del cart slice and slice assignment emptying the shared cart list so checkout is empty too
Both del cart[:] and cart[:] = [] leave cart and checkout empty, because the same list was edited in place.

How does this code work?

[:] selects every position in the list. del removes that whole range, and the assignment cart[:] = [] replaces the range with nothing.

Both edit the list in place, so checkout is emptied too. I prefer clear(), but you’ll see these forms in older code.

Why doesn’t my_list = [] clear the other variable?

This is the gotcha. Writing cart = [] doesn’t empty anything. It makes a new, empty list and points the name cart at it.

cart = ["laptop stand", "USB-C hub", "desk lamp"]
checkout = cart          # a second name for the SAME list

cart = []                # a brand-new empty list
print(cart)
print(checkout)          # the old list is untouched
print(cart is checkout)

Output:

[]
['laptop stand', 'USB-C hub', 'desk lamp']
False
Command Prompt output showing cart is an empty list while checkout still holds the three original items and cart is checkout is False
Reassigning cart gives it a new empty list, while checkout still holds the three original items.

How does this code work?

The old list still exists because checkout refers to it. Only the name cart moved, which is why cart is checkout is now False.

The same thing bites inside functions, where reassigning a parameter only changes the local name:

def reset_wrong(items):
    items = []           # rebinds the local name only

def reset_right(items):
    items.clear()        # empties the caller's list

cart = ["laptop stand", "USB-C hub", "desk lamp"]
reset_wrong(cart)
print("after reset_wrong:", cart)
reset_right(cart)
print("after reset_right:", cart)

Output:

after reset_wrong: ['laptop stand', 'USB-C hub', 'desk lamp']
after reset_right: []
Command Prompt output of two Python functions where reassigning a list parameter leaves the cart full but clear() empties it
reset_wrong() leaves the cart untouched, while reset_right() empties the caller’s list.

So use clear() when the function should empty the caller’s list. Reassigning is fine when nobody else holds the list, as in a fresh empty list you later check.

Picking the right way to clear a list

ApproachEmpties other references?Use it when
my_list.clear()YesAlmost always; clearest option
del my_list[:]YesOlder code, or Python 2 compatibility
my_list = []NoNobody else refers to the old list
while my_list: my_list.pop()YesYou need each removed item

If you only want to drop some items, not all of them, see removing elements from a list in Python.

Things to Keep in Mind When Clearing a List

  • my_list = [] doesn’t affect other names pointing at the old list. Use clear() if they should see an empty list.
  • clear() returns None. Writing cart = cart.clear() turns your list into None.
  • Clearing can’t be undone, so copy first with cart.copy() if you need the data.

Working with lists comes up constantly, so these are worth a look too:

Frequently asked questions

How do I clear a list in Python?

Call my_list.clear(). It empties the list in place and returns None.

What is the difference between clear() and my_list = []?

clear() empties the existing list, so every variable pointing at it sees an empty list. my_list = [] only points that one name at a new list.

Does del my_list[:] do the same as clear()?

Yes. Both remove every item in place. clear() is newer and easier to read.

How do I clear a list but keep a copy?

Copy it first with backup = my_list.copy(), then call my_list.clear(). The backup stays full.

Why does my function not empty the list I pass in?

Because items = [] rebinds the local name only. Use items.clear() inside the function.

Where is list.clear() documented?