循环遍历取出列表里的偶数,并存入一个新的列表。。
while循环
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b = 0
c = []
while b < len(a):
b += 1
if b % 2 == 0:
c.append(b)
print(c)a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b = 0
c = []
while b < len(a):
b += 1
if b % 2 == 0:
c.append(b)
print(c)
for循环
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
c = []
for b in a:
if b % 2 == 0:
c.append(b)
print(c)