1,函数嵌套调用
2.递归的理解
3.递归程序
4,递归需要注意点
#内存溢出
def sum_3_num(a,b,c):
return a+b+c
def avg_3_num(a,b,c):
result=sum_3_num(a,b,c)/3
return result
print avg_3_num(11,22,33)
2.递归的理解
def xxxx(num):
if num > 1:
return num * xxxx(num - 1)
else:
return num
def xxx(num):
if num>1:
return num * xxxx(num - 1)
else:
return num
def xx(num):
if num > 1:
return num * xxx(num - 1)
else:
return num
def get_num(num=4):
if num > 1:
return num * xx(num - 1)
else:
return num
get_num()
3.递归程序
def get_num(num=5):
if num > 1:
return num * get_num(num - 1)
else:
return num
print get_num(200)
4,递归需要注意点
#内存溢出
'''
def test():
print "hello"
test()
test()
'''
995 hello
996 hello
997 hello
998 hello
999 hello
1000 Traceback (most recent call last):
1001 File "test.py", line 4, in <module>
1002 test()
1003 File "test.py", line 3, in test
1004 test()
1005 File "test.py", line 3, in test
1006 test()