发布时间:2019-07-14 10:04:39编辑:auto阅读(1819)
总结:
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
49074
48210
38946
36073
30488
27279
26285
21106
20952
19295
165°
268°
186°
834°
903°
882°
895°
850°
811°
971°