Search code examples
pythonrecursionreturn

why does python print not working after return?


Why does print statement not run after I return in recursion in Python?

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)

Solution

  • **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.**