Python del 语句
Python del 语句语法:
del sth
可以删除掉一个变量,一个列表,一个列表中的键。。。等等等等。
实例:
>>> a = 5
>>> a
5
>>> del a
>>> a
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
a
NameError: name 'a' is not defined
>>> a =
>>> del a
>>> a
>>> del a
>>> a
>>> del a
>>> a
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
a
NameError: name 'a' is not defined
>>> a = {0: '0', 1: '1'}
>>> del a
>>> a
{1: '1'}
>>> del a
>>> a
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
a
NameError: name 'a' is not defined
>>> def func():
print("FUNC!")
>>> func()
FUNC!
>>> del func
>>> func()
Traceback (most recent call last):
File "<pyshell#35>", line 1, in <module>
func()
NameError: name 'func' is not defined
页:
[1]