def func(count):
count += 1
print('>'*count, count)
if count == 5: return count
res = func(count)
print('>'*count, res)
return res
func(0)
可以想象成平行的平面,函数调用向内层平面深入,return向外层平面返回(默认返回None),count就只是在平面内流动。
#斐波那契生成器
def fib(n):
if n == 1:
yield 1
else:
a, b = 1, 1
yield from (a,b)
while n>2:
n-=1
a, b = b, a+b
yield b
import time
for i in fib(1):
# time.sleep(0.5)
print(i)