在Python中构建列表时的自动递增

1 投票
2 回答
5349 浏览
提问于 2025-04-16 02:42

这是我目前的进展。我想知道有没有办法在列表构建的时候自动增加数字?这样我就可以得到 1, 2, 3, 4…… 而不是全是 1。

possible = []
possible = [1] * 100
print possible

谢谢,
诺亚

2 个回答

0

像这样吗?

start=1
count= 100
possible = [num for num in range(start,start+count)]
print possible
13
possible = range(1, 101)

请注意,最后的点(在这个例子中是101)会包含在结果列表中。

撰写回答