Recursion and Recursive Function in Python
Table of Contents
- What is Recursion in Python?
- What is Python Recursive Function?
What is Recursion in Python?
The practice of defining something in terms of itself is known as recursion. Place two parallel mirrors facing each other in the physical world as an illustration. Any item between them would be recursively mirrored.
What is Python Recursive Function?
We know that a function in Python can call other functions. It's possible that the function will call itself. Recursive functions are the name for these types of constructs.
def factorial(x): #This is a recursive function to find the factorial of an integer if x == 1: return 1 else: return (x * factorial(x-1)) num = 3 print("The factorial of", num, "is", factorial(num))