the for loop is generic iterator in pythonit can step through the items in any ordered sequence or other iterable object the for statement works on stringsliststuplesand other built-in iterablesas well as new user-defined objects that we'll learn how to create later with classes we met for briefly in and in conjunction with sequence object typeslet' expand on its usage more formally here general format the python for loop begins with header line that specifies an assignment target (or targets)along with the object you want to step through the header is followed by block of (normally indentedstatements that you want to repeatfor target in objectstatements elsestatements assign object items to target repeated loop bodyuse target optional else part if we didn' hit 'breakwhen python runs for loopit assigns the items in the iterable object to the target one by one and executes the loop body for each the loop body typically uses the assignment target to refer to the current item in the sequence as though it were cursor stepping through the sequence the name used as the assignment target in for header line is usually (possibly newvariable in the scope where the for statement is coded there' not much unique about this nameit can even be changed inside the loop' bodybut it will automatically be set to the next item in the sequence when control returns to the top of the loop again after the loop this variable normally still refers to the last item visitedwhich is the last item in the sequence unless the loop exits with break statement the for statement also supports an optional else blockwhich works exactly as it does in while loop--it' executed if the loop exits without running into break statement ( if all items in the sequence have been visitedthe break and continue statements introduced earlier also work the same in for loop as they do in while the for loop' complete format can be described this wayfor target in objectstatements if testbreak if testcontinue elsestatements assign object items to target exit loop nowskip else go to top of loop now if we didn' hit 'breakexamples let' type few for loops interactively nowso you can see how they are used in practice for loops