python-生成器
2015-09-26 23:15
567 查看
__author__ = 'holoto' if __name__ == '__main__': def dd(): # 生成器 print('the function start-first')#function start c = 1 print('the function start')#function start while True: print('the while runing')#while runing c = c + 2 print('the pre of yield') #print(c) yield c print('the while end') print('the function end')#the function end d = dd() print(dd()) print(next(d)) print(next(d)) print(next(d)) print(next(d)) print(next(d))
程序运行
/usr/bin/python3.4 /root/PycharmProjects/test/d.py
生成器函数地址--<generator object dd at 0x7f9d226f3168>
第一次运行
the function start-first
the function start
the while runing
the pre of yield
3
第二次
the while end
the while runing
the pre of yield
5
第三次
the while end
the while runing
the pre of yield
7
第四次
the while end
the while runing
the pre of yield
9
第五次
the while end
the while runing
the pre of yield
11
Process finished with exit code 0
相关文章推荐
- python处理文件
- 生日悖论的Python实现
- Python游戏引擎开发(二):创建窗口以及重绘界面
- 20150926 kaggle Titanic入门篇excel&python.md
- 【Python】使用 multiprocessing.dummy 执行多线程任务
- python - bing_api_search
- 我的python学习笔记(2) - GDAL与Python
- Python 安装boto boto3
- mysql-python 安装错误: Cannot open include file: 'config-win.h': No such file or directory
- 学习python处理python编码问题
- python编码
- 使用 Python 连接 Caché 数据库
- 【python】自己编写的Set类
- Python __init.py__文件
- python 2 和 python 3
- Python变量和对象
- Python包管理pip工具在Mac OSX10.10上的安装及lxml安装错误的解决办法
- 用python发布一条微博
- 使用 python3 环境开发。
- Python大数据依赖包安装