Grant Edwards grante at
Sat Feb 15 00:42:45 CET 2003

In article <b2jsir$csa$1 at>, Daniel Silva wrote:

> What is the purpose of the del statement?

To delete things.  :)

> Why would you want to undefine a variable?  More precisely, how
> many programs would be broken if a python compiler did not
> implement it?

Many of mine would.

I often use it to delete items from a list or dictionary:

>>> x = [1,2,3,4]
>>> del x[1]
>>> x
[1, 3, 4]

>>> d
{3: 'three', 2: 'two', 1: 'one'}
>>> del d[2]
>>> d
{3: 'three', 1: 'one'}

Grant Edwards                   grante             Yow!  Well, I'm on the
                                  at               right planet---everyone
                                 looks like me!!!

More information about the Python-list mailing list