Python Recursion

 

Python Recursion

We can let the function call itself, such a process is known as calling a function recursively in python.

 

Example:


def factorial(num): 
    if (num == 1 or num == 0):
        return 1
    else:
        return (num * factorial(num - 1)) 
  
# Driver Code 
num = 7; 
print("number: ",num)
print("Factorial: ",factorial(num))

 

Output:

number:  7
Factorial:  5040