It is a method in python that clears all the content of the list. It empties the existing list. It doesn’t return a value. This method won’t work for Python 3.2 and below. You have to use del operator instead. This method doesn’t take any parameters in it.
Syntax:
list.clear()
Example 1:
s = [“Name“, “codewindow“, “Country“, “India“] s.clear() print(s)
Output:
[]
Explanation:
It emptied the existing list by clearing all the items inside it.
Example 2:
s = [{10, 2}, (‘code‘), [‘10.1’, ‘2.8’]] s.clear() print(s)
Output:
[]
Explanation:
It emptied the existing parent list by clearing all the items inside it.