python的函數(shù)可以有返回值,也可以沒有返回值。函數(shù)需要先定義后調(diào)用,函數(shù)體中return語句的結(jié)果就是返回值。如果一個(gè)函數(shù)沒有reutrn語句,其實(shí)它有一個(gè)隱含的return語句,返回值是None,類型也是'NoneType'。
例如
defshowplus(x):
print(x)
returnx+1
num=showplus(6)
add=num+2
print(add)
輸出結(jié)果為
6
9
隱含return的情況
defshowplus(x):
print(x)
num=showplus(6)
print(num)
print(type(num))
輸出結(jié)果
6
None
以上內(nèi)容為大家介紹了python培訓(xùn)之函數(shù)有返回值嗎,希望對(duì)大家有所幫助,如果想要了解更多Python相關(guān)知識(shí),請(qǐng)關(guān)注IT培訓(xùn)機(jī)構(gòu):千鋒教育。