新聞中心
在定義函數(shù)時(shí),對(duì)于return的使用

大名網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),大名網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為大名成百上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的大名做網(wǎng)站的公司定做!
return語句是python語言中函數(shù)返回的一個(gè)值,每個(gè)函數(shù)都應(yīng)該有一個(gè)返回值,其中,return返回值可以是一個(gè)數(shù)值,一個(gè)字符串,
一個(gè)布爾值,一個(gè)列表,或者函數(shù)。
在Python中return函數(shù)返回值return,函數(shù)中一定要有return返回值才是完整的函數(shù),如果你沒有定義Python函數(shù)返回值,
那么得到的結(jié)果是None對(duì)象。
return 的簡(jiǎn)要使用說明
(1)返回函數(shù)的返回值
(2)終止程序的運(yùn)行,提前退出,
例如
#函數(shù)中沒有return時(shí) def test(a,b): print(a+b) result=test(1,2) print(result) type(result) [out]: 3 None #函數(shù)中存在return時(shí) def test(a,b): print(a+b) return(a+b) result=test(1,2) print(result) type(result) [out]: 3 3
python學(xué)習(xí)網(wǎng),大量的免費(fèi)python學(xué)習(xí)視頻,歡迎在線學(xué)習(xí)!
當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:python中return如何定義
網(wǎng)頁網(wǎng)址:http://www.5511xx.com/article/ccidcge.html


咨詢
建站咨詢
