标签:show pop 删除 move color eve click http 列表
l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘] name = l1.pop(1)#返回被删除的值,按索引去删除 print(name,l1)
若不写删除元素索引,默认删除最后一个
l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘] l1.remove(‘asda‘) print(l1)
l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘] l1.clear() print(l1) del l1 print(l1)
del 的用法
l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘] del l1[1:2] print(l1)
l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘] l1[1] = ‘shdiau‘ l1[2] = [2,4,5] print(l1)
l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘] for i in l1:#查列表中的每一元素 print(i)
l1 = [‘das‘, ‘dfsdf‘,[1,23,],‘asda‘] for i in l1:#查列表中的每一元素 print(i) print(l1[0:2])#切片查,查列表前两个元素
标签:show pop 删除 move color eve click http 列表
原文地址:https://www.cnblogs.com/zly9527/p/11216092.html