Python List clear()

In this tutorial, we will see about Python List‘s clear method.Python List clear method is used to remove all the items from the list.

Python List clear example

You can simply use clear method to delete all the items from the list.Python extend does not return anything but it actually updates the original list.
Let’s understand this with the help of simple example.

Output:

List before clear: [1, 2, 3, 4] List after clear: []

If you are using python 3.2 or below, you won’t find clear method in the list.You need to use del operator in that case.

Output:

List before clear: [1, 2, 3, 4, 5] List after clear: []

That’s all about Python List clear method.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *