
Paste_Image.png
返回生成器对象

Paste_Image.png
所以程序调用后无输出

Paste_Image.png
生成器对象和迭代器对象类似,都支持可迭代接口,next函数

Paste_Image.png
输出结果

Paste_Image.png
再次调用next函数

Paste_Image.png
输出结果

Paste_Image.png
再调用两次next函数

Paste_Image.png
输出结果,1-3次正常,第4次抛出停止迭代异常

Paste_Image.png
生成器对象也是可迭代对象,可以放在in关键字后边

Paste_Image.png
运行结果

Paste_Image.png
结论:生成器对象既实现可迭代接口又生成迭代器接口(next),所以返回的就是它自身

Paste_Image.png
输出结果

Paste_Image.png
判断素数程序

Paste_Image.png
测试用例

Paste_Image.png
最终结果

Paste_Image.png