lst=[10,20,30,40,50,60,30]
lst.remove(30)#从列表中移除一个元素,如有重复只删除第一个元素
print(lst)#[10, 20, 40, 50, 60, 30]
#lst.remove(100)#ValueError: list.remove(x): x not in list
#pop()根据索引移除元素
lst.pop(1)
print(lst)
#lst.pop(5)#IndexError: pop index out of range角标越界
lst.pop()#如果不指定参数(索引),将删除列表中最后一个元素
print(lst)
print('------------切片操作-删除至少一个元素,将产生一个新的列表对象——————————')
new_list=lst[1:3]#从下表1开始,不包括3
print('原列表:',lst)
print('切片后的列表',new_list)
print('不产生新的列表对象,而是删除原列表中的内容')
lst[1:3]=[]#从下表1开始,不包括3
print(lst)#不是真的删除,是用[]将列表中的元素替代
print('清空列表中的所有元素')
lst.clear()
print(lst)
print('del语句将列表对象删除')
del lst
print(lst)#name 'lst' is not defined
列表元素的修改操作



