Category Archives:

Recursive Functions in Python

Monday, April 8th, 2013
Posted in Joel by Joel Gross

I spent the weekend learning more about Python on Udacity.com. I went through Unit 6 which was all about recursive procedures in Python.

A recursive function is basically a function that calls itself.  An example of this would be:

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)

Recursion is great because it allows you to write code that is much simpler and cleaner than if you had to write the same code using if/while procedures.