当前位置:网站首页>Generator parameters incoming parameters

Generator parameters incoming parameters

2022-07-06 08:33:00 MAR-Sky

The generator can be send Method to pass in parameters

send function : Pass in parameters to The last time yield End assignment position variable , And execute to the next yield Location

def  easy_gen():
	print('start...')
	m = yield 10
	
	print('mid')
	print(m)
	n = yield 20
	print(n)
	print('end')
	yield 30

gen = easy_gen() #  Get the variable that points to the function 
gen.__next__()   #  return 10
gen.send('adga')

 Insert picture description here
Be careful ,__next__() The method is to yield The next number returns ,

原网站

版权声明
本文为[MAR-Sky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060827241781.html