why del is not a function or method?

Skip Montanaro skip.montanaro at gmail.com
Mon Oct 16 12:28:40 EDT 2017


> What about del team[2]?
>
> There is no name involved here, and even a reference to team[2] won't help.

(I'm not sure quite what question is asking. Apologies if my
assumption was incorrect.)

That is precisely why del is a statement. At byte-compile time, both
"team" and "2" are available. The easiest way to see this is to define
a simple function:

def f(team):
    del team[2]

Now, import the dis module and call

dis.dis(f)

then check out the byte code assembler statements.

Skip



More information about the Python-list mailing list