生成器都是迭代器,迭代器不一定是生成器 def fansik(max): n, before, after = 0, 0, 1 while n < max: print(before) before, after = after, before + after n += 1 fansik(10) 生成器方式 def fansik(max): n, before, after = 0, 0, 1 while n < max: yield before before, after = after,…
十三. Python基础(13)--生成器进阶 1 ● send()方法 generator.send(value) Resumes the execution, and "sends" a argument which becomes the result of the current yield expression in the generator function. The send() method, like __next__(), returns the next v…
十二. Python基础(12)--生成器 1 ● 可迭代对象(iterable) An object capable of returning its members one at a time. Examples of iterables include all sequence types (such as list, str, and tuple) and some non-sequence types like dict and file and objects of any clas…