A recursive function is one that calls itself. Recursion is a way of solving a problem by reducing it to a smaller version of the same problem, solving that, and building the answer back up. The factorial of n (written n!, the product of all integers from 1 to n) is the standard example: n! equals n times (n - 1)!, and 1! is 1. The definition refers to itself, so the code can too. Recursion is not a special Python feature; it simply follows from the fact that a function body may call any function that exists when it runs, including itself.
Keep reading for free
Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.