GNU Info

Info Node: (python2.1-tut.info)del statement

(python2.1-tut.info)del statement


Next: Tuples and Sequences Prev: More on Lists Up: Data Structures
Enter node , (file) or (file)node

The `del' statement
===================

There is a way to remove an item from a list given its index instead of
its value: the `del' statement.  This can also be used to remove slices
from a list (which we did earlier by assignment of an empty list to the
slice).  For example:

     >>> a
     [-1, 1, 66.6, 333, 333, 1234.5]
     >>> del a[0]
     >>> a
     [1, 66.6, 333, 333, 1234.5]
     >>> del a[2:4]
     >>> a
     [1, 66.6, 1234.5]

`del' can also be used to delete entire variables:

     >>> del a

Referencing the name `a' hereafter is an error (at least until another
value is assigned to it).  We'll find other uses for `del' later.


automatically generated by info2www version 1.2.2.9