def great(a,b,c):
if(a>b and a>c):
print("a is greater")
elif(b>a and b>c):
print("b is greater")
else:
print("c is greater")
a=great(12,3,1)
print(a)
你能解釋為什么沒有列印輸出嗎?
uj5u.com熱心網友回復:
在 python 縮進問題中,您的函式呼叫沒有正確縮進,這就是它不列印任何內容的原因
def great(a,b,c):
if(a>b and a>c):
print("a is greater")
elif(b>a and b>c):
print("b is greater")
else:
print("c is greater")
a=great(12,3,1)
print(a)
uj5u.com熱心網友回復:
因為你的great函式正在回傳None。
這是解決方案:
def great(a,b,c):
if(a>b and a>c):
print("a is greater")
elif(b>a and b>c):
print("b is greater")
else:
print("c is greater")
great(12,3,1)
uj5u.com熱心網友回復:
函式 great() 不回傳任何內容。在 python 中,當函式中沒有回傳任何內容時,將回傳默認的“無”值。所以使用時:
a=偉大的(12,3,1)
它回傳無值。該值被分配給 a。因此,當您列印 a 時,您會得到 None。
查看此鏈接了解更多資訊:
https://realpython.com/python-return-statement/#:~:text=Implicit return Statements,-A Python function&text=That default return value will always be None .&text=如果 you don't supply,None as a return value .
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/415091.html
標籤:
上一篇:用于選擇特定行的Python輸入
下一篇:為什么這似乎回傳一個陣列?
