Sep-26-2020, 08:12 AM
I have been reading up on the "yield" instead of "return" statement.
Arguably, I understand what it does.
On most sites however, they give the generic(?) example of how to
print the squares of the numbers from 1 to 10 using a def function with a while loop etc..
They need 10 lines of code for that yield example (even taking out the comment lines)
Anybody can print those squares in 2, let alone 1 line of code.
Question: could somebody describe - in words only - a situation where using "yield"
provides a huge benefit?
thx,
Paul
Arguably, I understand what it does.
On most sites however, they give the generic(?) example of how to
print the squares of the numbers from 1 to 10 using a def function with a while loop etc..
They need 10 lines of code for that yield example (even taking out the comment lines)
Anybody can print those squares in 2, let alone 1 line of code.
Question: could somebody describe - in words only - a situation where using "yield"
provides a huge benefit?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.