首页 > 编程语言 > 详细

python摘记

时间:2016-11-08 02:14:28      阅读:346      评论:0      收藏:0      [点我收藏+]

iterator支持两种builtin types:__iter__ 和 next,资料:https://docs.python.org/2/library/stdtypes.html#iterator.next

generator:https://wiki.python.org/moin/Generators

generator和iterator的区别:http://stackoverflow.com/questions/2776829/difference-between-pythons-generators-and-iterators

yield in python:http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/index.html

例如

class Fab(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()

 

python摘记

原文:http://www.cnblogs.com/autoria/p/6041224.html

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