6.5 del 语句 The del statement

del_stmt  ::=  "del" target_list
Download entire grammar as text.

Deletion is recursively defined very similar to the way assignment is defined. Rather that spelling it out in full details, here are some hints.

删除与赋值的定义方法类似, 也是递归的. 下面是一些的说明:

Deletion of a target list recursively deletes each target, from left to right.

一个目标表的递归删除操作会从左到右地删除其中的每个对象地.

Deletion of a name removes the binding of that name from the local or global namespace, depending on whether the name occurs in a global statement in the same code block. If the name is unbound, a NameError exception will be raised.

删除名字就是在局部名字空间和全局名字空间删除掉该名字的绑定(必须存在), 从哪个名字空间删除决定于该名字是否出现在其代码块的globals语句中.

It is illegal to delete a name from the local namespace if it occurs as a free variable in a nested block.

Deletion of attribute references, subscriptions and slicings is passed to the primary object involved; deletion of a slicing is in general equivalent to assignment of an empty slice of the right type (but even this is determined by the sliced object).

对于属性引用, 下标和片断的删除会作用到相关的主元对象, 对片断的删除一般等价于对该片断赋予相应类型的空片断(但这也受被截为片断的对象的限制).