In python, can we decrement the control variable in for loop? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

In python, can we decrement the control variable in for loop?

From what I have observed, the for loop in Python doesn't need a separate code to increment the control variable but how do I decrement the control variable in the loop. Can I do it without writing a separate code for it?

19th Jun 2018, 3:13 PM
Gokulram Ramesh
Gokulram Ramesh - avatar
1 Resposta
+ 4
You just need a negative step for example... #30->21 for i in range(30, 20, -1): print(i)
19th Jun 2018, 3:16 PM
TurtleShell
TurtleShell - avatar