Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

list.clear

Removes every element of a list in place.

Version: Python 3.14; repository image, production runtime not attested

Syntax

a.clear()

Removes every element of a list in place.

Other names referring to the same list immediately observe the empty collection.

Removing all items changes the shared outer list. Therefore the alias prints an empty list. Assigning a new empty list to the first name would instead leave the alias pointing to the old contents. The method returns None.

a = [0]
alias = a
assert a.clear() is None and alias is a and alias == []

Examples

a = [3, 5]
view = a
print(a.clear())
print(view)

Result

None
[]

Removing all items changes the shared outer list. Therefore the alias prints an empty list. Assigning a new empty list to the first name would instead leave the alias pointing to the old contents. The method returns None.

Sources