python的递归函数

python的递归函数写起来就两个点

1.当前数与上一个结果的关系

2.起始数值

举例子

求n的阶层

def fun(n):
    if n==0:              #起始值
        return 1
    return n*fun(n-1)    #递归关系

a=5
print("5的阶层是:",fun(a))

非常好理解

原文地址:https://www.cnblogs.com/mghhzAnne/p/11232465.html