发布时间:2019-07-14 10:04:39编辑:auto阅读(1828)
总结:
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
49176
48326
39048
36169
30575
27376
26374
21203
21045
19385
175°
183°
287°
485°
331°
1008°
1020°
1009°
1010°
961°