"""可迭代:可循环--一个实现了next方法的对象则是迭代器 一类是集合数据类型,如list/tuple/dict/set/str 一类是generator,包括生成器和带yield的generator function""" from collections import Iterable isinstance({},Iterable) class Fibs: def __init__(self): self.a=0 self.b=1 def __next__(self): self.a, self.b= self.b, self.a+self.b return self.a def __iter__(self): return self fibs=Fibs() for i in fibs:#由于Fibs可迭代,所以fibs可迭代 if i<100: print (i)