In this chapter, we will present iterations using loops and iterators. We will show examples of how this can be used with lists and generators. Iteration is one of the fundamental operations a computer is useful for. Traditionally, iteration is achieved with a for loop. A for loop is a repetition of a block of instructions a certain number of times. Inside the loop, you have access to a loop variable, in which the iteration number is stored.
A for loop in Python is primarily designed to exhaust a list, that is, to repeat the same sequence of commands for each element of that list. The effect is similar to the repetition effect just described if you use a list containing the first integers.
A for loop only needs one element of the list at a time. It is therefore desirable to use a for loop with objects...