Hey,
This is an example of a generator function:
=====
def counter(start_a t=0):
count = start_at
while True:
val = (yield count)
if val is not None:
count = val
else:
count += 1
======
5
9
======
I'm not able to understand how this generator function is working,
would you please me (what happens when calling next/send)?
Thanks.
This is an example of a generator function:
=====
def counter(start_a t=0):
count = start_at
while True:
val = (yield count)
if val is not None:
count = val
else:
count += 1
======
>>count = counter(5)
>>count.next( )
>>count.next( )
>>count.send( 9)
======
I'm not able to understand how this generator function is working,
would you please me (what happens when calling next/send)?
Thanks.
Comment