马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Python del 语句
语法:
可以删除掉一个变量,一个列表,一个列表中的键。。。等等等等。
实例:
>>> 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 = [1,2,3,4,5]
>>> del a[4]
>>> a
[1, 2, 3, 4]
>>> del a[0]
>>> a
[2, 3, 4]
>>> 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[0]
>>> 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
|