Does anyone here know what for in python does? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Does anyone here know what for in python does?

I've searched lots of websites all they say is it's for loop.

8th Nov 2016, 7:49 PM
Atom Bomb
Atom Bomb - avatar
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")
10th Nov 2016, 8:35 AM
Sunera Avinash
Sunera Avinash - avatar
+ 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
8th Nov 2016, 8:18 PM
Cristi Vlad
Cristi Vlad - avatar
0
Does it just do that or are there other ways on doing it?
8th Nov 2016, 10:14 PM
Atom Bomb
Atom Bomb - avatar