The del statement

Michael Torrie torriem at gmail.com
Fri May 9 10:38:57 EDT 2008


George Sakkis wrote:
> I think you're trying to imply that it is consistent with setting a
> value (same with getting). I guess what bugs me about "del" is that
> it's a keyword and not some universally well-known punctuation. Do you
> you feel that Python misses a "pop" keyword and respective
> expressions ?

Typically the word "pop" has a different meaning than you describe.
Most programmers think of pop in conjunction with push, for working with
FIFOs.  Normally pop would not be expected to take any arguments, or
maybe an argument of a number describing how many items to pop off of a
FIFO (stack).  Thus I don't think a pop method would be the right way to
go here.

I don't feel python misses a pop keyword because pop is already used as
methods of classes implementing stacks and FIFOs where appropriate.

> 
> (1) pop x: Remove x from the current namespace and return it.
> (2) pop x[i]: Instead of x.pop(i)
> (3) pop x.a: Equivalent to "_y=x.a; del x.a; return y"

The confusion over del does stem from it's behavior, so I can see where
you're coming from.  del doesn't delete anything; it just removes a
name.  However pop would be just as confusing in my opinion, given that
it's already associated with data structures.



More information about the Python-list mailing list