+ 6
Thank you for answering my question.
I wrote a function expecting it to be a normal function, but... It's a generator, but the value of yielded is not what I expected. I know what the generator is. Thank you for answering the questions in the code. Oma Falk Vitaly Sokol visph Jan Markus https://code.sololearn.com/ckQWorm7KlFE/?ref=app
4 Réponses
+ 5
About return statement used in generators:
https://code.sololearn.com/cyVFL7qS4pF6/?ref=app
+ 2
What I think is any occurence of yield in a function makes it a generator and that's how you may understand it.
When we iterate through it, before yield could give out 5 the return statement ends the iteration returning 6 which is insignificant for a generator as it only cares for values given by yield.
+ 1
You can use a for loop
+ 1
#from PEP 255
def func():
try:
return
except:
yield 5
print(func())