I'm not sure if this is the right place to ask, but I was messing with recursive functions, and noticed that while attempting recursion 997 my script returned a recursion error. The script I wrote was the following,
def main(x):
print(x)
x += 1
return main(x)
main(0)
After looking about online I opened the interpreter(?) in the powershell and tried sys.getrecursionlimit()
and it returned 1000, I tried adding the same thing to the above script and it also returned 1000. So why did the error pop up before 1000 recursions? Did I write the function incorrectly or is there something else going on? If it helps, this is the full error message I got,
...
990
991
992
993
994
995
996
Traceback (most recent call last):
File "test.py", line 6, in <module>
main(0)
File "test.py", line 4, in main
return main(x)
File "test.py", line 4, in main
return main(x)
File "test.py", line 4, in main
return main(x)
[Previous line repeated 992 more times]
File "test.py", line 2, in main
print(x)
RecursionError: maximum recursion depth exceeded while calling a Python object
Thanks!