+ 2
"for x in list" Assigns each list item to an x, Then how does it work "for i in range (10):" and why do you need "i"??
just don't have to explain to me that "for i in range (10)" repeats the cycle 10 times, I know that.
12 ответов
+ 16
range() is a functions that generates numbers upto the limit
Here ,
for i in range(10)
In this after in* you can use anything which u need to iterate ,we use range() because range can have 1 2 or 3 parameters
>If range(10) // then it generates 0 to 9
>If range(1,10) //then it generates same number but starting point will be 1 ...so it will be 1 to 9
>If range(1,10,2) // then it will start from 1 and adds 2 for each iteration...it generates 1,3,5,7,9....
And "i" is a variable which we use to step each element as iteration flows in the list ,tuple or watever which is valid for the for loop!
I hope u will understand;)
+ 4
1. For i in list =>
i = element of the list
2. For i in range(len(list)) =>
i = number that represents index
so here list[i] = element of the list!
It is more preferrable to use the 2nd option because in the first option the index is unknown but in the second option both element and index are known!
+ 3
иван refer to this
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_func_range.asp
And also look at this
https://code.sololearn.com/cj1msmHdsefv/?ref=app
+ 2
You need a variable to use that specific value in further lines..
+ 2
range(10) is a returns an iterable of value from 0 to 10-1.
So each value is assigned to i in a iterable way...
i =0
..
..
i = 9
+ 1
I changed the question
+ 1
I don't fully understand how "for i in range" works
+ 1
in case of range,
it is loop!!! it iterates the same code, function, logic, comparison whatever you put in loop.... from start to end...
Usually start point is 0 and step is 1, but you can define other start point and step
+ 1
иван In a cycle way, in each cycle the temparary variable is assigned next value so that is called here as a current iterative value..
In for i in range(10):
initially i is assigned 0.
In next ireation, I assigned next value 1, so this repeats until reach max value.. For all these itraration code in loop executed..
If still not clear, then Do you asking about loop or range function? Or
write that code and observe output of that.. You can understand it more clearly..
+ 1
for i in range(10) has a similar meaning to for(i=0,i<10,i++) in other languages
0
i, x are tempary user defined variables there. You can use any valid variable.
Ex :
for num in range(10):
for j in range(10):
0
Jayakrishna🇮🇳 what does iterative value mean?