[Solved] Why i don’t get the maximum recursion number in python?


The default recursion limit is 1000.

>>> sys.getrecursionlimit()
1000

A program with a single recursive function will reach 999:

start = 0

try:
    def recursion():
        global start
        start += 1
        recursion()
    recursion()
except RecursionError:
    print('recursion :', start, 'times')

prints out

recursion : 999 times

Your program is creating a stack that has recursion(), then repeat(), then recursion(), etc., and a print() call, so it makes sense you reach a bit under half of that.

3

solved Why i don’t get the maximum recursion number in python?