Recursion happens when a function calls itself to solve a smaller version of the same problem.
def countdown(n):
if n == 0:
print("Done!")
else:
print(n)
countdown(n - 1)
This prints , , , , , Done! Each call handles one number, then delegates the rest.
Two key parts:
Base case: Stops recursion. Here, n == 0.
Recursive case: Calls itself with a smaller problem. Here, countdown(n - 1).
Without a base case, recursion runs forever until Python crashes with "maximum recursion depth exceeded."