新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python函數(shù)有返回值嗎
Python的函數(shù)可以有返回值,也可以沒有返回值。函數(shù)需要先定義后調(diào)用,函數(shù)體中 return 語句的結(jié)果就是返回值。如果一個(gè)函數(shù)沒有 reutrn 語句,其實(shí)它有一個(gè)隱含的 return 語句,返回值是 None,類型也是 'NoneType'。

例如
def showplus(x): print(x) return x + 1 num = showplus(6) add = num + 2 print(add)
輸出結(jié)果為
6 9
隱含return的情況
def showplus(x): print(x) num = showplus(6) print(num) print(type(num))
輸出結(jié)果
6 None
更多學(xué)習(xí)內(nèi)容,請點(diǎn)擊Python學(xué)習(xí)網(wǎng)。
網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:python函數(shù)有返回值嗎
URL標(biāo)題:http://m.fisionsoft.com.cn/article/djdceop.html


咨詢
建站咨詢
