Why Python raises RecursionError before it exceeds the real recursion limit?

Your recursive() function is not the only component that counts towards the limit. Some Python internals also increase the counter, because Python code can cause them to be called multiple times too. The print() function is one of them.

Bottom line is that the recursion limit doesn’t only apply to the Python functions you wrote. It applies to the whole call stack.

Leave a Comment