我正在编写一个返回该odd positions
列表中元素的代码。当我运行我的程序时,它没有显示任何输出。但是当我替换它时return lst2
,return print(lst2)
它会向我显示所需的输出。所以我的问题是为什么我的程序在我写的时候没有显示任何输出return lst2
?
def op(lst):
lst2=[]
for i in lst:
indx=lst.index(i)
if indx%2==1:
lst2.append(i)
return lst2
a=[22, 5, 7, 35, 1, 100, 15]
op(a)