Python 3 reference · List Methods

Python List clear() Method

Remove every item from the list in place, leaving an empty list. Other references see the change too.

Python 3 Since 3.0

Syntax

list.clear()

Return value

None.

Examples

Empty a listTry it yourself
cart = ["tea", "cake"]
cart.clear()
print(cart, len(cart))

Output

[] 0
clear() vs assigning []Try it yourself
a = [1, 2, 3]
b = a          # same list
a.clear()
print(b)
c = [1, 2, 3]
d = c
c = []        # new list; d is unchanged
print(d)

Output

[]
[1, 2, 3]

Version history

VersionChange
Python 3.0Added