Recursive Functions

Want to learn more? I recommend these Python books: Python for Data Analysis, Python Data Science Handbook, and Introduction to Machine Learning with Python.

Simple factorial


Recursive function

The tell-tale sign of a recursive function is a function that calls itself

# Create a function inputing n, that,
def factorial(n):
    # if n is less than or equal to 1,
    if n <= 1:
        # return n,
        return n

    # if not, return n multiplied by the output
    # of the factorial function of one less than n
    return n*factorial(n-1)

# run the function