尾遞歸:指最後一步(不一定是最後一行)調用另一個函數
#函數test01在test02中爲尾調用
def test01(x):
print(x)
def test02(y):
y+=1
print(y)
return test01(x) #程序執行到這裏,test02的狀態將不會保留,因爲跳轉到test01(x)時已是最後一步
#函數test01在test02中爲零尾調用
def test01(x):
return x
def test02(y):
y+=1
print(y)
return test01(x)+1 #程序執行到這裏,test02的狀態將會保留,因爲跳轉到test01(x)時已是最後一步