Skip to main content

Python 函数的递归

Published 1 min readMarkdown
Python 函数的递归

函数的递归

什么是递归函数

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

递归的定义方法

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

递归函数的说明

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

代码

# 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()

1 view

No comments yet. Be the first to comment.

More from this blog