if you need to modify the sequence you are iterating over while inside the loop (for example to duplicate selected items)it is recommended that you first make copy iterating over sequence does not implicitly make copy the slice notation makes this especially convenientfor in words[:]loop over slice copy of the entire list if len( words insert( wwords ['defenestrate''cat''window''defenestrate'with for in words:the example would attempt to create an infinite listinserting defenestrate over and over again the range(function if you do need to iterate over sequence of numbersthe built-in function range(comes in handy it generates arithmetic progressionsfor in range( )print( the given end point is never part of the generated sequencerange( generates valuesthe legal indices for items of sequence of length it is possible to let the range start at another numberor to specify different increment (even negativesometimes this is called the 'step')range( range( range(- - - - - - to iterate over the indices of sequenceyou can combine range(and len(as followsa ['mary''had'' ''little''lamb'for in range(len( ))print(ia[ ] mary had little lamb in most such caseshoweverit is convenient to use the enumerate(functionsee looping techniques strange thing happens if you just print range more control flow tools