+ 1
for loop counter variable
Hi, Does for loop in python only works with ranges? Is there a way to do a loop with variable control like in c or java or is it only possible using a while loop? Java example for(int i=0;i<X;i++)
2 Antworten
+ 2
for i in range(x):
# code
will result in basically the same as the for loop you have.
You can also loop over a collection such as a list.
lst = ['a', 'b', 'c',...]
for item in lst:
# code
0
Nope, not possible explicitly.
for e in range(0, X, 1):
is basically the same thing, though you could strip off the third argument of the range function.