Iterators throw exception handling

= L [1,2,3,4,5 ] 
A = L. the __iter__ () 

  # Print (Next (A)) 
  # Print (Next (A)) 
  # Print (Next (A)) 
  # Print (Next (A )) 
  # Print (the Next (a)) 
  # Print (the Next (a)) # the above list is only five lengths, while more than you print the error is reported. As the case of processing, the error will not 

the while True:
      the try : 
         Item = A. __Next__ ()
          Print (Item)
      the except the StopIteration: # exception handling 
         break

 

Guess you like

Origin www.cnblogs.com/li33232/p/11440404.html