Python Tutorial Python Advanced Python References Python Libraries

Python List - clear() Method



The Python clear() method is used to delete all elements of the specified list.

Syntax

list.clear()

Parameters

No parameter is required.

Return Value

None.

Example: Clear all elements of a list

In the example below, the list clear() method is used to delete all elements of the list called MyList.

MyList = [10, 50, 50, 100, 1000, 1000]

MyList.clear()      
print(MyList)

The output of the above code will be:

[]

❮ Python List Methods