clear() – delete all entries in list

  1. The first line of the code creates a list named myList and assigns it the values [1, 2, 3, 4, 5].
  2. The second line of the code calls the clear method on the myList object. The clear method is used to remove all elements from a list. In this case, all elements in myList are removed.
  3. The print function is used to print the value of myList. Since myList is an empty list, it will simply print [].

So, the code creates a list, removes all its elements, and then prints the empty list.

myList = [1, 2, 3, 4, 5]
myList.clear()

print(myList)
Output
[]