在其他语言中很少有这个关键字,那么为什么要让它做关键字呢?好奇了一下。这是google的答案,由于没有使用过,只是在这里记录下别人的意见,以后再做探讨。
No.1
can't really think of any reason why python needs the del keyword (and most languages seem to not have a similar keyword). For instance, rather than deleting a variable, one could just assign None to it. And when deleting from a dictionary, a del method could be added.
Is there any reason to keep del in python, or is it a vestige of Python's pre-garbage collection days?
Firstly, you can del other things besides local variables
del list_item[4]del dictionary["alpha"]
Both of which should be clearly useful. Secondly, using del on a local variable makes the intent clearer.
del foo
foo = None
I know in the case of del foo that the intent is to remove the variable from scope. Its not clear that foo = None is doing that. If somebody just assigned foo = None I might think it was dead code. But I instantly know what somebody who codes del foo was trying to do
From:http://stackoverflow.com/questions/6146963/when-is-del-useful-in-python
No.2
这是所有关键字:
The following is a list of keywords for the Python programming language.
and del from not while
as elif global or with
assert else if pass yield
break except import print
class exec in raise
continue finally is return
def for lambda try
print to console
while
controlling the flow of the program
for
iterate over items of a collection in order that they appear
break
interrupt the (loop) cycle, if needed
continue
used to interrupt the current cycle, without jumping out of the whole cycle.
New cycle will begin.
if
used to determine, which statements are going to be executed.
elif
stands for else if.If the first test evaluates to False,
then it continues with the next one
else
is optional. The statement after the else keyword is executed,
unless the condition is True
is
tests for object identity
not
negates a boolean value
and
all conditions in a boolean expression must be met
or
at least one condition must be met.
import
import other modules into a Python script
as
if we want to give a module a different alias
from
for importing a specific variable, class or a function from a module
def
used to create a new user defined function
return
exits the function and returns a value
lambda
creates a new anonymous function
global
access variables defined outside functions
try
specifies exception handlers
except
catches the exception and executes codes
finally
is always executed in the end. Used to clean up resources.
raise
create a user defined exception
del
deletes objects
pass
does nothing
assert
used for debugging purposes
class
used to create new user defined objects
exec
executes Python code dynamically
yield
is used with generators