About generator in Python
This question already has an answer here:
The call print(next(fib(6)))
always creates a new instance of the fib
generator and yields one value from it, you then discard it.
On the other hand:
f = fib(6)
print(next(f))
print(next(f))
print(next(f))
creates an instance f
of the generator fib
and yields three values from it.
Also, using max
as the parameter name is frowned about since, in the local scope at least, you're masking a built-in function that has the same name.
上一篇: python打印内部vs外部功能?
下一篇: 关于Python中的生成器