named enumerate does the job for us--its net effect is to give loops counter "for free,without sacrificing the simplicity of automatic iterations 'spamfor (offsetitemin enumerate( )print(item'appears at offset'offsets appears at offset appears at offset appears at offset appears at offset the enumerate function returns generator object-- kind of object that supports the iteration protocol that we will study in the next and will discuss in more detail in the next part of the book in shortit has method called by the next built-in functionwhich returns an (indexvaluetuple each time through the loop the for steps through these tuples automaticallywhich allows us to unpack their values with tuple assignmentmuch as we did for zipe enumerate(se next( ( ' 'next( ( ' 'next( ( ' 'we don' normally see this machinery because all iteration contexts--including list comprehensionsthe subject of --run the iteration protocol automatically[ for (icin enumerate( )[''' ''aa''mmm'for (ilin enumerate(open('test txt'))print('% % (il rstrip()) aaaaaa bbbbbb cccccc to fully understand iteration concepts like enumeratezipand list comprehensionsthoughwe need to move on to the next for more formal dissection why you will careshell commands and more an earlier sidebar showed loops applied to files as briefly noted in python' related os popen call also gives file-like interfacefor reading the outputs of spawned shell commands now that we've studied looping statements in fullhere' an example of this tool in action--to run shell command and read its standard output textpass the command as string to os popenand read text from the file-like object it returns loop coding techniques