from collections import Iterator
# lt = [i for i in range(10)]
lt = (i for i in range(10))
print(isinstance(lt, Iterator)) #判断是否是迭代器 True
from collections import Iterable, Iterator
lt = [1, 2, 3]
# 将一个可迭代对象转换为迭代器
lt = iter(lt)
print(isinstance(lt, Iterable)) # True
print(isinstance(lt, Iterator)) # True
Python 迭代器的判断
最新推荐文章于 2024-10-15 08:05:30 发布