+ 5

When it says import random for i in range(5): value = random.randint(1, 6) print(value) What does the 'i' mean?

Sorry if I sound stupid

7th Apr 2016, 5:14 AM
Bam Morgan
Bam Morgan - avatar
12 Respuestas
+ 6
I think 'for i in range(5)' means 'for every item in range(5)'. The 'i' could be any letter or word so you could write 'for num in range(5)' and then 'num' would be each number in the range you have created. I think of 'i' as a placeholder for each item in the list that follows.
8th Apr 2016, 9:16 AM
nashyboots
+ 5
"i "is a simple name, you can replace it with any kind of letters. it represent the index of all value in range. when you type | for i in range ...| is the same as you tell the pc |for all value in range indexed by "i" name...|
8th Apr 2016, 9:47 AM
Marco Carone
Marco Carone - avatar
+ 4
i is a temporary variable
12th Dec 2016, 12:28 PM
55633
+ 1
in the programing world,we usually using the letters I,j, k in for and while loops.you could replace it with just num for example,but it is a "tradition"
12th Dec 2016, 1:43 PM
ArbyZ D.M
ArbyZ D.M - avatar
+ 1
I like to think of i as meaning iteration or index, even though it is just a variable. That's just how I think of it when I see it, so I actually use i as the variable for for loops most of the time, unless I am worried about code readability or am looping through key/vals or such.
12th Dec 2016, 7:54 PM
Nick Bowling
Nick Bowling - avatar
+ 1
like Marco says "i" is thé index of all the values in range. Here web have range(6) consider lit ligne an array of 6 elements and "i" will take the value between 0 and 5 such that 0 is the index of de first box like wise and 5 ils the last box.
14th Dec 2016, 8:41 AM
Mossolo Michel Maximilien
Mossolo Michel Maximilien - avatar
+ 1
"i" just stands for any interger value within the given range
27th Dec 2016, 7:20 PM
Nicolas Baha
Nicolas Baha - avatar
0
"i" is just a counter, that passes values from 1 to 5, and for each time the program carries out some actions (calls a module "random" and prints the result of processing). Here "i" is like a metronome.
17th Aug 2016, 11:59 AM
Angailin Xsanael
Angailin Xsanael - avatar
0
As mentioned by the other users. It's an increment with the index name 'i' . It helps to name similar to the range your cycling through eg for car in vehicles. P.S. Your never stupid for asking it's a good networking tool to ask.
2nd Dec 2016, 9:25 AM
Chad Mitchell
Chad Mitchell - avatar
0
As everyone said, I is just a counter variable, so you could just use _ to tell Python to ignore the result of the current iteration of range
11th Dec 2016, 10:06 AM
Amaras A
Amaras A - avatar
0
the 'i' here is just a temporary variable.
13th Dec 2016, 7:19 PM
Djaber Meghar
Djaber Meghar - avatar
0
for i in range(5): means i=0 to i=4
14th Jun 2020, 4:20 PM
Aditya Kumar
Aditya Kumar - avatar