本文以一个简单的实例讲述了python实现斐波那契数列数列递归函数的方法,代码精简易懂。分享给大家供大家参考之用。
主要函数代码如下:
def fab(n):
if n==1:
return 1
if n==0:
return 0
else:
result=int(fab(n-1))+int(fab(n-2))
return result
Copy after login
测试代码如下:
for i in range(10):
print fab(i)
Copy after login
希望本文所述对大家Python程序设计的学习有所帮助。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn