How do I loop backward using indices in Python?

0 votes

I want to loop from 100 to 0, how do I do it?

for i in range (100,0) #this is not working
Jul 3 in Python by Shabnam
• 920 points

1 answer to this question.

0 votes


You can make use of negative indices to start from back:

for i in range(100):
    k = 100 - i

Or You can use:

for i in reversed(range(101)):

Both will give same output that is 100 to 0

answered Jul 3 by Taj
• 1,040 points

Related Questions In Python

0 votes
1 answer

How can I use indices in math using python

Operator ^ is a bitwise operator, which does "bitwise exclusive or". More: The ...READ MORE

answered Dec 11, 2018 in Python by ariaholic
• 7,340 points
0 votes
1 answer
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 348 views
+4 votes
6 answers
+1 vote
1 answer

How can I reverse list in Python?

Reversing a list is a commonly used ...READ MORE

answered May 13 in Python by Taj
• 1,040 points
0 votes
1 answer

How to put time delay in Python?

You can use sleep() method to sleep ...READ MORE

answered May 28 in Python by Taj
• 1,040 points