VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • Python无限递归的概念教程

Python程序调用自身的这种方法叫做递归,如果达不到我们需要的条件,而它会永远的继续递归调用下去,而程序也会永远不停止,这种现象叫做Python的无限递归

下面玩蛇网(www.iplaypy.com)给大家写一个会引起无限递归的简单函数:

?
1
2
def test():
    test()

很多程序语言中,无限递归的函数方法并不会真正的无休止的运行下去,它们都有一个深度限制,Python编程语言会在递归深度到达上限时,引发一个异常的错误信息:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> test()
 
Traceback (most recent call last):
  File "pyshell#3", line 1, in module
    test()
  File "pyshell#2", line 2, in test
    test()
  File "pyshell#2", line 2, in test
    test()
  File "pyshell#2", line 2, in test
    test()
  File "pyshell#2", line 2, in test
    test()
RuntimeError: maximum recursion depth exceeded

这个调用回溯信息显示了它的错误类型和详细信息,这个版本的Python无限递归最大值为 1000,各版本限制值不太相同。

浏览Python无限递归的概念教程的用户还在关注:学python看什么书

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/jinjie/jj176.html


相关教程