Python List clear()

The clear() method removes all items from the list.

Example


Syntax of List clear()

The syntax of clear() method is:

list.clear()

clear() Parameters

The clear() method doesn't take any parameters.


Return Value from clear()

The clear() method only empties the given list. It doesn't return any value.


Example 1: Working of clear() method

Output

List: []

Note: If you are using Python 2 or Python 3.2 and below, you cannot use the clear() method. You can use the del operator instead.


Example 2: Emptying the List Using del

Output

List: []

Visit this page to learn how del operator works in Python.