List Clear Method – Remove all items from a List

Spread the love

List Clear Method –

The list clear method removes all the items from a list.

Syntax of Clear –

list.clear()

How clear works –


In [1]: numbers = [1, 2, 3, 4, 5]

In [2]: # remove all items from the list

In [3]: numbers.clear()

In [4]: numbers
Out[4]: []

Remove all items using del –

You can also remove all items from a list using the del keyword.

In [5]: numbers = [1, 2, 3, 4, 5]

In [6]: del numbers[:]

In [7]: numbers
Out[7]: []

Rating: 1 out of 5.

Leave a Reply