How to Call Function Itself in Python


In this example we will show how to call the function itself in Python.

Source Code

def factorial(n):
    if n == 1:
        return 1         # the recursion ends
    return n * factorial(n - 1)  # minus one, recursive call

print(factorial(5))

Output:

120
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments