+ 3
What is differenxe between return and yield ???
4 Respuestas
+ 6
Yield is a keyword like return, except it returns a generator.
https://pythontips.com/2013/09/29/the-JUMP_LINK__&&__python__&&__JUMP_LINK-yield-keyword-explained/
+ 4
It's matter of memory. Yield creates generator. Return do not. Generators are very useful when you have huge iterable objects. They do not stay in the memory ready for more after doing what they are suppose to do. Doesn't really matter when the object is for example few thousands of records long. Sometimes there maybe millions!
Hire is a nice expenation
https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do
+ 3
Yield and return are kind of similar - but yield is for a generator. Basically (if I understand correctly) a generator only returns a value when requested, and it's only valid for a single use - it only exists for the line it's called on. Supposed to be good for situations where you handle large data sources or items without a finite length - but I haven't applied it anywhere myself.
+ 1
hi