Python List clear()
source link: https://thispointer.com/python-list-clear/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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.
Advertisements
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.
Advertisements
Thanks for reading.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK