递归函数
"""
递归函数:基线条件和递归条件
递归条件:函数调用自己。
基线条件:是函数结束循环,避免无限循环
"""
# 倒计时
def countdown(i):
print(i)
if i <= 1:
return
else:
countdown(i-1)
countdown(3)
# 栈
def greet(name):
print('hello, '+ name +'!')
greet2(name)
print('getting ready to say bye...')
def greet2(name):
print('how are you, ' + '?')
def bye():
print('ok bye !')
greet('maggie')
# 递归调用栈
def fact(x):
if x == 1:
return 1
else:
return x*fact(x-1)
print(fact(3))
3
2
1
hello, maggie!
how are you, ?
getting ready to say bye...
6
来源:CSDN
作者:陨星落云
链接:https://blog.csdn.net/qq_28368377/article/details/103642167