Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

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

Asked by Joseph Slater Apr 10, 2021 1.6K views 1 answer
Share

About this question

I have this tail-recursive function here:

def fib(n, sum):

    if n < 1>

        return sum

    else:

        return fib(n-1, sum+n)

c = 998

print(fib(c, 0))

It works up to n=997, then it just breaks and spits a "maximum recursion depth exceeded in comparison" RuntimeError. Is this just a stack overflow? Is there a way to get around it?

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.