this is the code:
def counter(start=0):
n = start
while True:
result = yield n
print(type(result), result)
if result == 'Q':
break
n += 1
c = counter()
print(next(c))
print(c.send('Wow!'))
print(next(c))
print(c.send('Q'))
and this is the output:
0
<class 'str'> Wow!
1
<class 'NoneType'> None
2
<class 'str'> Q
Traceback (most recent call last):
File "gen.send.py", line 14, in <module>
print(c.send('Q')) # F
StopIteration
I can understand why the type line is being printed ( <classs '.....' ......>) but I don't understand why the iteration number is being printed (0, 1 and 2) cause there isn't any programming line to print it, can someone please explain that to me ?😕
Mark
You have
print(next(c))and
cyields the index