在任何函数都有返回值,一般都是想到return 关键词,在函数生成器中有个关键词 yield 也可以做返回值,在函数没调用之前,是不会输出任何东西的
1,return 用法
def stu():
return 'hello'
stu()
2,yield用法
def stu():
a,b=1,1
b=a+1
yield b
return 'hello'
stu()
文章来自 http://www.96net.com.cn/
在任何函数都有返回值,一般都是想到return 关键词,在函数生成器中有个关键词 yield 也可以做返回值,在函数没调用之前,是不会输出任何东西的
1,return 用法
def stu():
return 'hello'
stu()
2,yield用法
def stu():
a,b=1,1
b=a+1
yield b
return 'hello'
stu()
文章来自 http://www.96net.com.cn/
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。