# 定义一个列表,包含元素:1,2,3,4,5,6,7,8,9,10
# 把是偶数的元素放入一个新列表中
mylist = [1,2,3,4,5,6,7,8,9,10]
index = 0
youlist = []
while index<len(mylist):
num = mylist[index]
if num % 2 == 0:
youlist.append(num)
index += 1
print(youlist)
# for循环实现
mylist = [1,2,3,4,5,6,7,8,9,10]
ylist = []
for i in mylist:
if i % 2 == 0:
ylist.append(i)
print(youlist)
标签:10,mylist,youlist,index,元素,列表 From: https://www.cnblogs.com/mmds/p/16942185.html