Skip to content

A function that calls itself

Read · 1 of 3

Two parts

A recursive function solves a smaller version of the same problem, then finishes the job: 4! = 4 × 3!.

It needs a base case where the answer is known directly (1! = 1). Without it, Python stops with a RecursionError.