for index in range(0, 10, 2):
print(index)
Why is the output 2,4,6,8?
How is it specified to only print evens? Is this what index does? My understanding was that index means position.
>Solution :
As was explained in the comments, the word index is just a variable name here. Yes, normally index refers to the position of an element in an iterable, however, that is not related to anything occurring in the code snippet in question.
Only the evens are printed as a result of the built-in range function. The third parameter, in this case 2, specifies the "step," which basically says how many numbers to jump for each element in the iterable range constructs. Then those elements are iterated over and bound to index in order, thus you see your output.