首页 > 编程语言 > 详细

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

时间:2018-03-08 18:30:45      阅读:1105      评论:0      收藏:0      [点我收藏+]

环境: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

原文:https://www.cnblogs.com/Jesse-Li/p/8530084.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!