python yield send
来源:互联网 发布:packetsender mac 编辑:程序博客网 时间:2024/06/14 23:39
def cd(n):
while n>=0:
print("first n:"+str(n))
newn = yield n
print("second n:"+str(n))
print("fist newn:"+str(newn))
if newn is not None:
n = newn*2
else:
n-=1
print("second newn:"+str(newn))
y = cd(5)
for x in y:
print(x) #5 3 2 1
if x == 5:
while n>=0:
print("first n:"+str(n))
newn = yield n
print("second n:"+str(n))
print("fist newn:"+str(newn))
if newn is not None:
n = newn*2
else:
n-=1
print("second newn:"+str(newn))
y = cd(5)
for x in y:
print(x) #5 3 2 1
if x == 5:
y.send(2)
genertaor.send(value)
generator的send函数作用:恢复之前挂起的yield,并将参数value成为当前yield表达式的结果,send函数返回下一个yield的结果(相当于执行了一次next)
0 0
- python yield send
- python yield send
- python yield和send
- Python学习-yield浅析和send()函数
- Python yield生成器的send方法考察
- python--生成器:yield的表达式形式,send
- 关于Python生成器(Generator的yield、next、send)
- python yield send 一个容易犯错的地方
- Python:yield关键字以及next、send函数的作用
- 为什么python的yield第一次不能用send发送数据?
- 理解Python协程:从yield/send到yield from再到async/await
- python----yield
- Python yield
- python yield
- python yield
- python --yield
- Python yield
- Python -- yield
- 自定义modal动画
- ant jsch.jar 一个异常及解决方法
- 如何获取通知栏上的所有通知
- nginx虚拟主机配置
- POJ 2576 Tug of War
- python yield send
- 欢迎使用CSDN-markdown编辑器
- IOS:IOS UITabBarController storybroad 点滴笔记
- Ant classpath 指定类路径 编译程序引用第三方jar包
- eclipse xml 中提示
- Android Studio1.5 配置Android annotations
- 互联网带来的不安
- 动态规划:数塔问题
- SpringMVC-01 HelloWorld的基本流程