We have seen in the last lecture that recursion can be used to express a computational process that repeats itself.
In fact, recursion can bring about any repetition, and there are programming languages where recursion is the only mechanism you can do repetition.
However, in Python, there is a limit on the number of recursive function calls: you cannot have more than 1,000 levels of function calls.
For example, calling the following function with $n = 1,000$ would result in a run-time error.
def print123(n): if n > 0: print123(n-1) print n print123(1001)
This limit exists because, for each level of function call, the interpreter needs to keep track of the function’s information in a part of the memory call stack. The stack has limited space, so recursing too many level is not a good idea.
We’ll see another mechanism of doing repetitive computation in the next slide.