发布时间:2019-07-14 10:04:39编辑:auto阅读(1798)
总结:
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
48860
47917
38703
35855
30281
27031
26065
20898
20695
19060
494°
591°
602°
605°
584°
570°
632°
704°
826°
925°