Python List clear()

In this article, we will discuss about the usage details of clear() method of Python List.

Introduction

In Python, the list class provides a method clear(), to remove all elements from list.

Syntax of List clear()

The syntax of index() method of list is as follows,

list.clear()

Parameters

We don’t need to provide any argument in clear() method of List.

Returns

  • It does not return anything. Basically the return value is None.

Example of List clear()

Suppose we have a list of numbers, and we want to delete all elements from this list. For that, we will call the clear() method of List. For example,

listOfNumbers = [22, 11, 33, 44, 11, 55, 11, 88, 77]

# remove all elements from list
listOfNumbers.clear()

print(listOfNumbers)
print('Size of List is : ', len(listOfNumbers))

Output:

[]
Size of List is :  0

It deleted all the elements from list, and size of list is now zero.

Summary

We learned all about the clear() method of python List.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top