在任何函數都有返回值,一般都是想到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刪除。