Mar. 03, 2016

The del Statement

The del statement can be used to remove an item from a list by referring to its index, rather than its value. For example, if you have a list with five values, like this:
a = [1, 2, 3, 4, 5]

and you want to remove the second listed value (2), you can use del to do so. The second listed value has an index of 1, so to remove the value, the del syntax would need to look like this:
del a[1]

Now a will look like this:
a = [1, 3, 4, 5]

Recommended Python Training – DataCamp

For Python training, our top recommendation is DataCamp.

Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.

Datacamp has beginner to advanced Python training that programmers of all levels benefit from.

 



Read more about:
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, PythonForBeginners.com only recommend products or services that we try personally and believe will add value to our readers.