Low Orbit Flux Logo 2 D

Python How To Empty / Clear A List

There are times where you might want to just wipe all of the contents of an entire list. Python gives us a built in function to clear a list which makes situations like this easy. This is generally the option you should go with but you might want to be aware of some of the other techniques that achieve the same result.

To clear a list just call clear:


You should probably use the above method in most cases but there are also a few other methods that you could use. We are going to take a look at these here.

Delete every element in the list:

del list[:]

Set every element to zero:

list *= 0

Reinitialize the list:

list = []