问题遇到的现象和发生背景
通过while循环,在【1,2,3,4,5,6,7,8,9,10】中得到仅有偶数的列表,但我出错了
用代码块功能插入代码,请勿粘贴截图
def while_func():
list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
index = 0
list2= []
while index<len(list):
element = list[index]
if element % 2 == 0:
list2.append[element]
index+=1
print(f"通过while,源列表{list},取出偶数后的列表{list2}")
while_func()