Python List – clear()
Python list.clear() method removes all the elements from the list.
clear() method modifies the original list.
Syntax
The syntax to call clear() method on a list myList is
</>
Copy
myList.clear()
where
myListis a Python listclearis method name
Examples
Remove all Elements from List
In the following program, we initialize a list myList with some elements, and remove all the elements from the list using clear() method.
main.py
</>
Copy
#take a list
myList = ['apple', 'banana', 'cherry']
#remove all elements from the list
myList.clear()
print(f'myList : {myList}')
Output
myList : []
Conclusion
In this Python Tutorial, we learned how to clear a list (delete all elements) using list.clear() method.
