About 317,000 results
Open links in new tab
  1. Difference between Yield and Return in Python - GeeksforGeeks

    Oct 20, 2020 · Yield is generally used to convert a regular Python function into a generator. Return is generally used for the end of the execution and “returns” the result to the caller statement. It replace the return of a function to suspend its execution without destroying local variables. It exits from a function and handing back a value to its caller.

  2. What does the "yield" keyword do in Python? - Stack Overflow

    Oct 24, 2008 · Yield in Python used to create a generator function. Generator function behaves like an iterator, which can be used in loop to retrieve items one at a time. When a generator function is called, it returns a generator object without executing the function immediately.

  3. Difference between yield and return in Python

    Sep 22, 2021 · There are two major differences between the working of yield and return statements in python. Return statement stops the execution of the function. Whereas, yield …

  4. When to use yield instead of return in Python? - GeeksforGeeks

    Sep 8, 2022 · Return sends a specified value back to its caller whereas Yield can produce a sequence of values. We should use yield when we want to iterate over a sequence, but don’t want to store the entire sequence in memory.

  5. Yield vs Return in Python: A Comprehensive Guide

    Aug 26, 2023 · When a function encounters a yield statement, it returns the specified value to the caller – just like a return. But here’s the twist: instead of terminating the function, yield pauses it. The function’s state (including local variables) is saved, and execution is returned to the caller.

  6. Python yield vs. return: What is the Difference? - Codefather

    Sep 23, 2023 · The return keyword is used to immediately return one or more values from a function in Python. The yield keyword when used in a function returns an object called “generator object”.

  7. What are the Differences between Yield and Return in Python?

    May 4, 2023 · While implementing the yield statement, it must be noted that it hauls the function, and returns the value to the caller function. The yield statement can restart from where it is left …

  8. Yield in Python Tutorial: Generator & Yield vs Return Example

    Jan 25, 2024 · Yield vs. Return: It’s crucial to distinguish between yield and return in Python: return: Terminates the function and returns a single value to the caller. Subsequent calls to the function start from the beginning. yield: Pauses the function, allowing it to …

  9. Yield vs Return in Python: Unraveling the Differences

    Mar 28, 2025 · Understanding the differences between yield and return is crucial for writing efficient, scalable, and maintainable Python code. This blog post will delve into the fundamental concepts, usage methods, common practices, and best practices related to …

  10. Python yield vs return Explained in Detail with Examples

    Mar 16, 2019 · In Python, the return statement does not save any state and it simply returns value to the caller. When you need to produce a series of values for every time calling function, use yield statement.

  11. Some results have been removed