import sys print(sys.setrecursionlimit(100000))
def story(): print('从前有座山') story() story() RecursionError: maximum recursion depth exceeded while calling a Python object 递归的错误,超过了递归的最大深度
修改最大默认递归值
import sys sys.setrecursionlimit(1000000) n = 0 def story(): global n n += 1 print(n) story() story()
递归函数实现斐波拉且数列:
def fib(n): if n == 1 or n == 2: return 1 else: return fib(n - 1) + fib(n - 2) print(fib(20))