>>> def f1(): for i in range(5): print i >>> def f2(): for i in range(5): return i >>> def f3(): for i in range(5): yield i >>>f1()01234>>>f2()0>>>print f2() #只会返回第一个元素0>>>f3() #相当于一个list>>>for m in f3(): print i 01234
本文共 390 字,大约阅读时间需要 1 分钟。
>>> def f1(): for i in range(5): print i >>> def f2(): for i in range(5): return i >>> def f3(): for i in range(5): yield i >>>f1()01234>>>f2()0>>>print f2() #只会返回第一个元素0>>>f3() #相当于一个list>>>for m in f3(): print i 01234
转载于:https://my.oschina.net/MrYx3en/blog/406979