想看详细内容的可转: https://www.cnblogs.com/liusouthern/p/8074383.html
以下指示几个注意事项,参数到底是索引还是元素?
pop()方法: 按照下标索引删除指定的值
s = ['how', 'are', 'you']
s.pop(0)
print(s)
['are', 'you']
remove()方法:按元素删除指定的值
s = ['how', 'are', 'you']
s.remove('are')
print(s)
['how', 'you']
del:删除列表、也可以进行切片删除
删除列表:
s = ['how', 'are', 'you']
del [s]
打印结果为空
切片删除:
s = ['how', 'are', 'you']
del s[0:2]
print(s) # ['you']
s = ['how', 'are', 'you']
s[1]="old"
print(s) # ['how', 'old', 'you']