1. pop(index) 是按索引号来删除列表中对应的元素,并返回该元素。
该函数的参数是索引号,也可以是空的,即pop(), 这时将最后一个元素删除。
>>> listA = ['a', 'b', 'c','a', 'b', 'c', 'a', 'b','c']
>>> w = listA.pop(3)
>>> w
'a'
>>> print(listA)
['a', 'b', 'c', 'b', 'c', 'a', 'b', 'c']
2. remove(参数) 是根据参数在列表中查找,若找到某个元素的值和参数相等,则将该元素删除,若没有找到,则抛出异常,该函数的参数不能为空,函数没有返回值。
>>> listA = ['a', 'b', 'c','a', 'b', 'c', 'a', 'b','c']
>>> w = listA.remove('a')
>>> print(w)
None
>>> print(listA)
['b', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
3.del函数用于字符串的删除操作。
>>> del listA[1]
>>> print(listA)
['a', 'c', 'a', 'b', 'c', 'a', 'b', 'c']
>>> del listA[1:4]
>>> print(listA)
['a', 'c', 'a', 'b', 'c']
>>> del listA
>>> id(listA)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
id(listA)
NameError: name 'listA' is not defined