logo
  • 教程列表
  • SO官方文檔
  • Iterables 和 Iterators
    • Iterator vs Iterable vs Generator
    • 逐個提取值
    • 迭代整個可迭代
    • 僅驗證 iterable 中的一個元素
    • 什麼是可迭代的
    • 迭代器不是可重入的
  1. StackOverflow 文件
  2. Python Language 教程
  3. Iterables 和 Iterators
  4. 逐個提取值

逐個提取值

Created: November-22, 2018

從內建的 iter() 開始,通過迭代獲取迭代器,並使用 next() 逐個獲取元素,直到提示 StopIteration 表示結束:

s = {1, 2}   # or list or generator or even iterator
i = iter(s)  # get iterator
a = next(i)  # a = 1
b = next(i)  # b = 2
c = next(i)  # raises StopIteration
  • 迭代整個可迭代
  • Iterator vs Iterable vs Generator

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明