What is the maximum recursion depth in Python, and how to increase it?

前端 未结 17 2875
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:14

I have this tail recursive function here:

def recursive_function(n, sum):
    if n < 1:
        return sum
    else:
        return recursive_function(n-1         


        
17条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 05:07

    import sys
    sys.setrecursionlimit(1500)
    
    def fib(n, sum):
        if n < 1:
            return sum
        else:
            return fib(n-1, sum+n)
    
    c = 998
    print(fib(c, 0))
    

提交回复
热议问题