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