About 68 results
Open links in new tab
  1. What does the "yield" keyword do in Python? - Stack Overflow

    Oct 24, 2008 · When yield is used instead of a return in a python function, that function is turned into something special called generator function. That function will return an object of …

  2. python - Return and yield in the same function - Stack Overflow

    Oct 27, 2014 · @Zack In Python 2.x, it'd be a SyntaxError: SyntaxError: 'return' with argument inside generator.It's allowed in Python 3.x, but is primarily meant to be used with coroutines - …

  3. Python `yield from`, or return a generator? - Stack Overflow

    Dec 14, 2016 · This would be applicable for deciding whether to yield values or return a list of them, not whether to return or yield from another generator. – user2357112 Commented Jan …

  4. python - What is the difference between yield and return ... - Stack ...

    May 23, 2019 · with yield you use less memory - try to run second example with very big value and will use a lot of memory. And yield doesn't have to wait for full list which may need some …

  5. python - Why using yield instead of return in pytest fixtures?

    Oct 18, 2023 · I see why using yield keyword when we want to run our tests and then clean things up going back to the fixture and running some code after the yield statement. As the code …

  6. python - Difference among Yield vs. Print vs. Return - Stack Overflow

    Jul 5, 2021 · My another question is yield vs. print: if we want to save memories and hope to directly print out the results, then why don't we just use print to directly print out the result, like: …

  7. python - Return in generator together with yield - Stack Overflow

    The return value is not ignored, but generators only yield values, a return just ends the generator, in this case early. Advancing the generator never reaches the yield statement in that case. …

  8. python - yield slower than return. why? - Stack Overflow

    Jan 16, 2017 · The yield keeps returning the next result until exhausted while the complete calculation is always done fully so if you had a test that might terminate your calculation early, …

  9. python - How are yield and return different from one another?

    Oct 22, 2019 · It is, of course, called return. That said, C++ can achieve something similar to our yield example using static variables: int func() { static i = 0; return i++; } However, that is not to …

  10. In practice, what are the main uses for the "yield from" syntax in ...

    This still does not cover all the corner cases though. What happens if the outer generator is closed? What about the case when the sub-generator returns a value (yes, in Python 3.3+, …

Refresh