Recursive Functions in Python


Define functions that call themselves for tasks like traversing directories or calculating factorials.

Source Code

def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)
print(factorial(5))
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments