First, the iterator for the python list of for cycle, his internal principle: to see if the next element exists, if present, then take out, if not present, the exception is reported stopiteration. (Python internal to exception handled) Class listiterator (object) | Methods defined here: | | __getattribute__ (...) | x.__getattribute__ (' name ') <==> x.name | | __iter__ (...) &NBSP;|&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;X.__ITER__ () <==> iter (x) | | __length_hint__ (...) | private method returning an estimate of len (list (it)). | | next (...) | x.next () -> the next value, or Raise stopiterationlistiterator two, generator range is not generator and xrange is generator readlines not generator and The xreadlines is the generator >>> print range (ten) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> print xrange (Ten) xrange (10) The generator is created internally based on yield, i.e., created only when used by the generator, thus avoiding memory waste as in the following table: [13, 22, 6, 99, 11] please follow the rules to calculate:13 and 22 comparisons, place large values on the right, i.e.:[13, 22, 6, 99, 11]22 and 6 compares large values on the right side, i.e.:[13, 6, 22, 99, 11]22 and 99 , placing large values on the right side, that is: [13, 6, 22, 99, 11]99 and 42 compare large values on the right, i.e.:[13, 6, 22, 11, 99,] 13 and 6 compare large values on the right side, i.e.: [6, 13, 22, 11, 99,]
Python study day2 Cont.-3