列表【33 55 79 40 88】移除列表中的所有偶数,并将新数列输出
看下程序
old = [33, 55, 79, 40, 88]
new = []
for i in old:
if i % 2 != 0:
new.append(i)
print(new)
# 方法二列表推导式
print([i for i in old if i % 2 != 0])
x = [33,55,79,40,88]
ret = [temp for temp in x if temp%2!=0]
print(ret)
直接遍历列表就好了
lst=[33, 55, 79, 40, 88]
res=[]
for number in lst:
if number %2 != 0:
res.append(number)
print(res)