1、递归函数
函数内部自己调用自己,需要一个出口,避免陷入死循环
例如1:
def num_list(first, end):
"""递归:打印first-end的值"""
if first == end:
print(end)
else:
print(first)
first += 1
num_list(first, end)
num_list(1, 3)
>>>1 2 3
例如2:
def num_list(first, end):
"""递归:累加first-end的值"""
if first == end:
return end
else:
return first + num_list(first + 1, end)
num_add = num_list(1, 3)
print(num_add)
标签:end,函数,list,add,num,print,相关,first
From: https://www.cnblogs.com/wangfengzi/p/17138258.html