Program to clear the list using different methods using Python


In this section of python programming, we will discuss the different ways to clear the list. Python provides four ways to clear :

  • Using clear(): Clear the list to size zero (empty list)
  • Using reinitialization: Reinitializing the list with empty value
  • Using *=0: Removes all the element
  • Using delete statement: Deletes all the values if no range is provided (i.e. list[:])


Program to clear the list using different methods


list1 = ['is', 'at', 'around', 'in', 'the' ]

list2 = ['red', 'blue', 'black', 'green', 'grey']

list3 = [1, 2, 3, 4, 5]

list4 = [6, 9, 10, 7, 11]

# Using clear

print("Elements in list1: ",list1)


print("Elements after using clear():",list1)


print("Elements in list2: ",list2)

list2 = []

print("Elements after using reinitialization:",list2)

# Using *= 0

print("Elements in list3: ",list3)

list3 *= 0

print("Elements after using *= 0:", list3)

# Using del

print("Elements in list4: ",list4)

del list4[:]

print("Elements after using del:",list4)


Program to clear the list using different methods Output


In the above python code we have created four lists with different values. We have used the different ways (mention above) to clear the list.


  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.

    View all posts


Leave a Reply

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.