Python 3.6 TypeEror: iter() returned non-iterator of type

Posted Jesse_Li

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 3.6 TypeEror: iter() returned non-iterator of type相关的知识,希望对你有一定的参考价值。

环境:Python 3.6

class Fabs(object):
    def __init__(self,max):
        self.max = max
        self.n, self.a, self.b = 0,0,1
        
    def __iter__(self):
        return self
    
    def next(self):
        if self.n < self.max:
            r = self.b
            self.a,self.b = self.b, self.a+self.b
            self.n = self.n+1
            return r
        raise StopIteration()
for key in Fabs(3):
    print (key)

原因是 Python 3 中没有next(), 而是__next__(self) 代替

以上是关于Python 3.6 TypeEror: iter() returned non-iterator of type的主要内容,如果未能解决你的问题,请参考以下文章