1,2,3,"sai",2,3,1]
>>> myList.remove(2)
>>> 我的列表
['prem', 1, 3, 'sai', 2, 3, 1]
>>> myList.remove(4)
回溯...(最近一次调用最后一次):
文件“”,第 1 行,在
ValueError: list.remove(x): x 不在 list2 中
2、使用list对象的pop方法。...>>> myList.pop(1)
1
>>> 我的列表
['prem', 3, 'sai', 2, 3, 1]
>>> myList.pop(7)
回溯(最近一次调用最后一次):
文件“<stdin...myList[2]
>>> 我的列表
['prem', 3, 2, 3, 1]
>>> del myList[1:3]
>>> 我的列表
['prem', 3, 1]
>>> del myList[7]
回溯...(最近一次调用最后一次):
文件“”,第 1 行,在
IndexError:列表分配索引超出范围
以上就是python列表删除项目的方法,希望对大家有所帮助。