17841

迭代器

from collections import Iteratorfrom collections import Iterableclass Classmate(object): def __init__(self): self.prev = 0 self.curr = 1 # def add(self, name): # ret = self.names.append(name) # return ret def __iter__(self): return self def __next__(self): value = self.curr self.curr += self.prev self.prev = value return valueif __name__ == '__main__': c = Classmate()

来源:博客园

作者:Victor_JJ

链接:https://www.cnblogs.com/victorstudy/p/11425896.html

Recommend