发布时间:2019-07-14 10:04:39编辑:auto阅读(1886)
总结:
for循环内部index(指针)每次循环自增1,删除的元素的索引会上移
lst = ['大鹏展翅','天道酬勤','前程似锦']
for el in lst:
if el in ['天道酬勤','前程似锦']:
lst.remove(el)
print(lst)
错误结果:
['大鹏展翅', '前程似锦']
lst = ['大鹏展翅','天道酬勤','前程似锦']
del_lst =[]
for el in lst:
if el in ['天道酬勤','前程似锦']:
del_lst.append(el)
for el in del_lst:
lst.remove(el)
print(lst)
正确结果:
['大鹏展翅']
上一篇: Python 异常处理
下一篇: 3G是什么?——让我们了解3G
50039
49296
39957
36996
31391
28233
27192
21982
21932
20265
365°
283°
266°
441°
435°
1048°
1959°
1818°
1459°
2925°