for i in range(5): | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

for i in range(5):

What is the i part of this code for?

28th Feb 2017, 2:12 AM
Jamal Bee
Jamal Bee - avatar
5 Answers
+ 9
it represents the current iteration of whatever it's in. so if you do: for i in range(0,5): print (i) it'll print each number it reaches the max(5) 0 1 2 3 4 you can name "i" anything though edit: fixed it raj
28th Feb 2017, 5:58 AM
Ahri Fox
Ahri Fox - avatar
+ 3
it is just a variable , it could be called anything : ex: for nums in range(5): print(nums)
28th Feb 2017, 2:26 AM
Jay
Jay - avatar
0
In my opnion.i is more like a flag begin with 0.as the tips says for in python is more like foreach in other language.
1st Mar 2017, 1:33 PM
Jonyhy
Jonyhy - avatar
- 1
@ahri your loop will print from 0 to 4.
28th Feb 2017, 5:59 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar
- 2
do you know this one: for (int I=0; I <5; I++) { }
28th Feb 2017, 2:57 AM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar