+ 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

8th Oct 2021, 1:30 AM
Amir
Amir - avatar
4 Respostas
+ 5
About return statement used in generators: https://code.sololearn.com/cyVFL7qS4pF6/?ref=app
8th Oct 2021, 2:36 AM
Vitaly Sokol
Vitaly Sokol - avatar
+ 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.
9th Oct 2021, 6:58 AM
abhinav
abhinav - avatar
+ 1
You can use a for loop
9th Oct 2021, 9:40 PM
CGO!
CGO! - avatar
+ 1
#from PEP 255 def func(): try: return except: yield 5 print(func())
11th Apr 2022, 3:32 AM
Harsha S
Harsha S - avatar