使用Python中的索引向后循环?
问题描述:
我正在尝试从100循环到0.如何在Python中做到这一点?
I am trying to loop from 100 to 0. How do I do this in Python?
for i in range (100,0)
不起作用.
答
尝试range(100,-1,-1)
,第三个参数是要使用的增量(已记录
Try range(100,-1,-1)
, the 3rd argument being the increment to use (documented here).
("range"选项,开始,停止,步骤已记录在这里)
("range" options, start, stop, step are documented here)