. 1 # the Author: CallMeV 2 # DATE: 2019-11-10 . 3 # Time: 10:43 . 4 . 5 # create iterators . 6 L = [1,2,3,4 ] . 7 D = ITER (L) # <list_iterator Object AT 0x000002AEA4DD4490> . 8 Print (D) . 9 Print (Next (D)) 10 Print (Next (D)) . 11 Print (Next (D)) 12 is Print (Next (D)) 13 is 14 15 # for loop do three things: 16 # 1, calls iter method returns an iterable 17 # 2, the continuous iterative call to the next object can be 18 # 3, the process StopInteration . 19 for I in [1,2,3,4 ]: 20 is Print (I) 21 is 22 is from Collections Import the Iterator 23 is Print (the isinstance ([1,2 ], List)) 24 Print (the isinstance (L, the Iterator)) 25 Print (the isinstance (D, the Iterator))
Iterator satisfy two conditions: 1 Method 2 has the next method has iter