Home  >  Article  >  Backend Development  >  python del()函数用法

python del()函数用法

WBOY
WBOYOriginal
2016-06-06 11:27:531946browse

示例程序如下:

>>> 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

>>>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn