简体   繁体   中英

Maximum level of recursion in Python

递归的最大级别是什么?如何在Python中更改它?

The default is 1000 levels deep and you can change that using the setrecursionlimit function in the sys module.

Warning:

Beware that some operating systems may start running into problems if you go much higher due to limited stack space.

Thought I will add a code example:

import sys
sys.setrecursionlimit(100000)

As Lizard noted, default is 1000 for a reason and the warning is important. Trying a high recursion limit on fibonacci(10000) ( return f(n-1) + f(n-2) ) was enough to shut down my Python IDE. Not getting the 'recursion depth reached' warning did not mean the problem was solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM