Skip to main content

Command Palette

Search for a command to run...

Day 24 - Recursion

Published
•1 min read•View as Markdown
V

I'm a Frontend Developer, passionate about learning about new Web Technologies.

Recursion in Python

Recursion is the process of defining something in terms of itself.

Python Recursive Function

In Python, we know that a function can call other functions. It is even possible for the function to call itself. These types of construct are termed as recursive functions.

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

More from this blog

Vivek's blog

34 posts