函数的递归

什么是递归函数

  • 一个函数不停的将自己反复执行

递归的定义方法

  • 通过返回值 直接执行自身函数

递归函数的说明

  • 内存溢出
  • 避免滥用递归

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# coding:utf-8

count = 0


def test():
global count
count += 1

if count < 5:
print('count条件不满足, 我要重新执行我自己! 当前count是%s' % count)
return test()
else:
print('count is %s' % count)


test()