您好,欢迎访问一九零五行业门户网

python del()函数用法

示例程序如下:
>>> a = [-1, 3, 'aa', 85] # 定义一个list
>>> a
[-1, 3, 'aa', 85]
>>> del a[0] # 删除第0个元素
>>> a
[3, 'aa', 85]
>>> del a[2:4] # 删除从第2个元素开始,到第4个为止的元素。包括头不包括尾
>>> a
[3, 'aa']
>>> del a # 删除整个list
>>> a
traceback (most recent call last):
  file , line 1, in
nameerror: name 'a' is not defined
>>>
其它类似信息

推荐信息