Python list.clear() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
list method

Definition

clear() removes every item, leaving an empty list []. The list object itself survives, so the change is in place.

Every other name, dict, or function argument that refers to the same list sees it empty too. That is the difference from lst = [], which only points one name at a brand-new list. del lst[:] does exactly what clear() does.

list.clear() is an instance method of the built-in list type: call it on a list with dot notation, such as thread.clear(...). No import is needed.

Syntax

Call it with no arguments; there is nothing useful to keep from the result.

python
lst.clear()
CallWhat it does
[1, 2, 3].clear()Returns None; the list becomes [].
del lst[:]Same effect as clear(): deletes every item of the same list.
lst = []Not the same: rebinds the name to a new list, and other references keep the old items.

clear() was added in Python 3.3, which is why older code often uses del lst[:]. del lst is different again: it deletes the name, not the items.

Method signatures
python
list.clear()
# returns: None; the list is now empty

Parameters

clear() takes no parameters.

Return Value

Return ValueDescription
NoneAlways None. The same list object is now empty, with length 0.

Python Examples

Example 1 — Clear One Chat Thread in an Inbox

The thread is stored inside a dict and also bound to a variable. Clearing through the variable empties the stored list.

python
inbox = {"alice": ["hi", "lunch?"], "bob": ["report sent"]}
thread = inbox["alice"]

print(thread.clear())
print(thread, len(thread))
print(inbox)
print(thread is inbox["alice"])

How It Works

  1. Two ways to reach one list. thread and inbox["alice"] refer to the same list object.
  2. No return value. clear() empties the list and returns None, which is what the first line prints.
  3. The dict sees it. Alice's messages are gone from the inbox too, while Bob's separate list is untouched.
  4. Still the same object. The identity check confirms clearing did not create a new list.

Example 2 — Empty a Shopping Cart That a Session Also Holds

Compare rebinding with = [], calling clear(), and deleting a full slice.

python
cart = ["shoes", "socks"]
session = {"cart": cart}

cart = []
print(session["cart"])

cart = session["cart"]
cart.clear()
print(session["cart"])

cart.extend(["hat", "scarf", "gloves"])
del cart[:]
print(session, cart == [])

How It Works

  1. Rebinding leaves data behind. cart = [] points the name at a new list, so the session still shows shoes and socks.
  2. clear() reaches the real list. After pointing cart back at the stored list, clear() empties the object the session holds.
  3. del with a full slice. del cart[:] removes all three new items from that same list, exactly like clear().
  4. Empty and equal. The session shows an empty cart, and cart == [] is True.

Example 3 — Flush a Sensor Buffer Every Three Readings

A helper saves a full batch and then clears the caller's list, so collection restarts from empty.

python
def flush(batch):
    print("saving", batch, "total", sum(batch))
    batch.clear()


buffer = []
for reading in [4, 8, 15, 16, 23, 42, 7]:
    buffer.append(reading)
    if len(buffer) == 3:
        flush(buffer)

print("left over:", buffer)

How It Works

  1. Fill to three. Each reading is appended, and when the buffer holds three values it is handed to flush().
  2. Totals. sum() gives 4 + 8 + 15 = 27 for the first batch and 16 + 23 + 42 = 81 for the second.
  3. Clearing the caller's list. batch is the same object as buffer, so batch.clear() empties it for the loop as well. Writing batch = [] would only change the local name.
  4. Partial batch. The seventh reading never reached three items, so it waits in the buffer.

Frequently Asked Questions

None. It empties the list in place, so there is nothing to assign.
clear() empties the existing list, so every reference sees it empty. lst = [] only makes the name lst point to a new list; other references keep the old items.
Yes, both delete every item from the same list object. del lst, without the slice, deletes the variable name instead.
No. The list still exists and can be reused; it simply has no items and a length of 0.
Call clear() on the parameter, as in batch.clear(). Assigning batch = [] inside the function only rebinds the local name and leaves the caller's list unchanged.

Next: list.copy()

Return a shallow copy: a new list that shares nested objects.

copy() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful