假设我在python shell中。我输入了= 10。
>>> a=10
>>> a
10
但c没有,我的意思是
>>> c
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'c' is not defined
>>>
如何清除a的值,以便它不应该存储任何内容。我的意思是在清除后如果按下输出应该类似于c。
注意:不要离开python。
答案 0 :(得分:2)
使用del
statement删除名称:
del a
之后访问a
也会引发NameError
:
>>> a = 10
>>> a
10
>>> del a
>>> a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined