0
Does anyone here know what for in python does?
I've searched lots of websites all they say is it's for loop.
3 Answers
+ 2
well it can go through all items in a list..
like in ->
lst = [3,7,5,0]
for i in lst:
print(i)
this prints all items in the list 'lst'
3
7
5
0
however this is mostly used when you need to do something for a certain number of times
think that you need to print "hello" for 100 times
you can use a for loop
for i in range(100):
print("hello")
+ 1
can you be more specific? yes, it is used when you want do repetitive stuff:
for i in range(5):
print(i)
which means for each value i in the range of 5 (for i form 0 to 5) print i
and the output will be
0
1
2
3
4
5
0
Does it just do that or are there other ways on doing it?