0
What does "for i in" mean?
What exactly does this mean? I see it in the python modules unit but I can't understand what this really means. Why the letter "i" as well? Below is one of the pieces of code that I cannot understand because of this. And is random & randint actual functions or predefined functions? import random for i in range(5): value = random.randint(1, 6) print(value)
2 Answers
+ 6
I'd rather say that "i" stands for "iterator", but that's not the point, it can be any variable name.
for x in y is an instruction to iterate the x variable over the y iterable collection. For example:
for l in "sololearn" will iterate over each character of the "sololearn" string :)
Oh, and randint() is a method of random module.
0
i is a variable standing for an Integer. It takes the value of an Integer in range 5 here. You could change it to another name, but you must change it in the loop block, to.
for x in range(5):
print (i)