I'm following a book and i ran into this sample program. I'm not sure how the numbers[position] in line 5 is working here? What is the relationship between position and numbers in that variable assignment?
numbers = [1, 3, 5] position = 0 while position < len(numbers): number = numbers[position] if number % 2 == 0: print "Found even number", number break position = position + 1 else: print "No even number found"
number = numbers[position]?for position in range(len(numbers)):or justfor number in numbers:, then I think you should find a better book.range(len(someseq))loops with indexing in the loop, thereby teaching new Python programmers the least Pythonic way to accomplish iterable iteration.