1
工作为什么if
不得在下列发电机为什么这个发电机不能在python
def mygen(m):
n = 0
if n < m:
n = n + 1
yield n
counter = mygen(5)
next(counter)
1
next(counter)
StopIteration
但while
做工作?
def mygen(m):
n = 0
while n < m:
n = n + 1
yield n
你是在比较一下吗? For循环与while循环相当。 –