這個問題在這里已經有了答案: 如何在函式中回傳后列印陳述句? (2 個回答) 昨天關門。
為什么我在 Python 中遞回回傳后 print 陳述句不運行?
arr=['zero','one','two','three','four','five','six','seven','eight','nine']
def numToWord(num):
if num==0:
return
dig=num%10
num=num//10
#print(arr[dig],end=" ")
return numToWord(num)
print(arr[dig],end=" ")
numToWord(345)
uj5u.com熱心網友回復:
**A return is a value that a function returns to the calling script or function when it completes its task.
So here return takes as a termination of this function. That's why it will not jump to next line.**
uj5u.com熱心網友回復:
return 的作業原理是結束函式,之后的所有內容都不會運行。我會將您的代碼更改為:
arr=['zero','one','two','three','four','five','six','seven','eight','nine']
def numToWord(num):
if num == 0:
return
dig = num % 10
num = num // 10
return dig,num
dig,num=numToWord(345)
print(arr[dig],end=" ")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/515664.html
標籤:Python递归返回
