英文文件:

next(iterator[, default])
Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised.
  返回可迭代物件中的下一個元素值
說明:
  
  1. 函式必須接收一個可迭代物件引數,每次呼叫的時候,返回可迭代物件的下一個元素。如果所有元素均已經返回過,則丟擲StopIteration 異常。
  1. >>> a = iter('abcd')
  2. >>> next(a)
  3. 'a'
  4. >>> next(a)
  5. 'b'
  6. >>> next(a)
  7. 'c'
  8. >>> next(a)
  9. 'd'
  10. >>> next(a)
  11. Traceback (most recent call last):
  12. File "<pyshell#18>", line 1, in <module>
  13. next(a)
  14. StopIteration

  2. 函式可以接收一個可選的default引數,傳入default引數後,如果可迭代物件還有元素沒有返回,則依次返回其元素值,如果所有元素已經返回,則返回default指定的預設值而不丟擲StopIteration 異常。

  1. >>> a = iter('abcd')
  2. >>> next(a,'e')
  3. 'a'
  4. >>> next(a,'e')
  5. 'b'
  6. >>> next(a,'e')
  7. 'c'
  8. >>> next(a,'e')
  9. 'd'
  10. >>> next(a,'e')
  11. 'e'
  12. >>> next(a,'e')
  13. 'e'