for循环中的list.remove()仅删除偶数项

时间:2018-09-19 10:43:11

标签: python python-3.x python-2.7

list = ["abc","cde","efg","ghi","ijk","klm"]
for x in list:
    print(x)
    list.remove(x)
print(list)

输出:

abc
efg
ijk
['cde', 'ghi', 'klm']

为什么此代码未删除列表中的所有项目? 有人可以解释一下

0 个答案:

没有答案