第七章第5讲:python函数的递归
1.递归:函数引用或调用自身的意思
# n的阶层 def calculate(n): result = n for i in range(1,n): # 1<=i<n result *= i return result print(calculate(4)) # 优化后的递归 def factorial(n): if n == 1: return 1 else: return n * factorial(n-1) print(factorial(4)) # 如下递归持续运行至崩溃 def fibs(): return fibs() fibs()