aList = [-1, -4, 6, 7, 3, 9, -11]
lis1 = [i for i in aList if i>=6 and i<9]
print(lis1)
lis2 = []
for i in aList:
if i >= 6 and i < 9:
lis2.append(i)
print(lis2)
lis3 = []
while aList != []:
li = aList.pop()
if li >= 6 and li < 9:
lis3.append(li)
print(lis3)
如果有用望采纳
return [x for x in alist if x>=6 and x<9]
new_list = []
for x in alist:
if x>=6 and x<9 :
new_list.append(x)
return new_list
n = 0
new_list = []
while alist[n]>=6 and alist[n]<9 :
new_list.append(alist[n])
n = n+1
if n >= len(alist):
break
return new_list
#如果有不对的,欢迎大家指点。万分感谢!