A recursive function calls itself on a smaller piece of the problem. Every recursive function needs two parts:
- a base case that answers directly without calling itself, like "an empty list sums to 0" or "the CEO has no manager";
- a recursive case that calls the function on something smaller, moving toward the base case.
Recursion fits nested data whose depth you don't know in advance: folders inside folders, lists inside lists, nested JSON, reporting chains.
Without a base case (or with a recursive call that never gets smaller), the calls never stop and Python raises RecursionError after about a thousand levels. For deep but simple repetition, a loop is usually the better choice.