Python range to list

前端 未结 4 1925
时光取名叫无心
时光取名叫无心 2020-12-16 18:52

I am trying to convert a range to list.

nums = []
for x in range (9000, 9004):
    nums.append(x)
    print nums

output

[90         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-16 19:13

    Since you are taking the print statement under the for loop, so just placed the print statement out of the loop.

    nums = []
    for x in range (9000, 9004):
        nums.append(x)
    print (nums)
    

提交回复
热议问题