I still couldn't understand the difference between using the return and yield statement. Could someone explain? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

I still couldn't understand the difference between using the return and yield statement. Could someone explain?

21st Jul 2016, 4:14 PM
Alonso
Alonso  - avatar
3 Answers
+ 14
Return is one time only. Yield works like a series of return statements, inside a generator.
24th Jul 2016, 7:09 PM
Ângelo Paulino
Ângelo Paulino - avatar
+ 5
I see so yield works same as return but just keeps returning values more than one time did I get it right?
25th Jul 2016, 6:27 AM
Alonso
Alonso  - avatar
+ 2
yes. if used with a loop calling it. if you call a generator once, the yield = return.
5th Aug 2016, 3:13 AM
scott williams
scott williams - avatar