有下面一段代码,分别打印 1 1 2 3 5 和 0 0 0 0 0,请问后面一个迭代器为什么不会打印 0 1 2 3 4 ?
class Fib(object):
def __init__(self):
self.prev = 0
self.curr = 1
def next(self):
value = self.curr
self.curr += self.prev
self.prev = value
return value
def __iter__(self):
return self
class T(object):
def __iter__(self):
return self
def next(self):
for i in range(5):
return i
f = Fib()
t = T()
print next(f)
print next(f)
print next(f)
print next(f)
print next(f)
print next(t)
print next(t)
print next(t)
print next(t)
print next(t)