1.循环遍历数组是,想添加条件修改时,只删除第一个
# -*- coding: utf-8 -*- a=[11,22,33,44,55] for i in a: if i == 11 or i ==22: a.remove(i) for i in a: print(i) ''' 22 33 44 55 [Finished in 0.1s] '''
2.应该引入被删除为一个数组
# -*- coding: utf-8 -*- a=[11,22,33,44,55] b=[] for i in a: if i == 11 or i ==22: b.append(i) for i in b: a.remove(i) for i in a: print(i) ''' 33 44 55 [Finished in 0.1s] '''