Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок+ 2
When I use for loop I type for I in list_name .. what is I !? Any one can show that to me !?
5 ответов
+ 11
The way a for works is like this:
for every_item in this_array
<loop this code>
So when you write:
for i in list_name
<your code>
i will stand for every item in list_name, from 0 to its last item, and loop until it uses all of the items. Ex: On the first loop, i = list_name[0]
+ 3
I believe it's short for iterator >> https://en.wikipedia.org/wiki/Iterator
Also, it doesn't actually need to be an 'i' - see these previous answers to a similar question >> https://www.sololearn.com/Discuss/207139/what-does-the-i-in-most-JUMP_LINK__&&__python__&&__JUMP_LINK-for-loops-stand-for
0
can you be little more clear ?
0
i is just a variable, it can be anything.
myList=[1,2,3]
for i in myList:
print(i)
output:
1
2
3
each time it loops, the variable i=the index of the list the loop is on. if the loop is on loop 0, i becomes myList[0].. the next time the loop runs, i becomes myList[1].. etc
0
i can be anything. Just notice:
Integer=int