---
title: "Yield does not work, but return does in Python why?"  
description: "Yield does not work, but return does in Python why?"  
author: "Utpal Vishwas"  
published: 2023-04-11  
updated: 2023-04-17  
canonical: https://www.mindstick.com/forum/157753/yield-does-not-work-but-return-does-in-python-why  
category: "python"  
tags: ["python", "python 2"]  
reading_time: 2 minutes  

---

# Yield does not work, but return does in Python why?

Yield does not work, but return does in [Python](https://www.mindstick.com/articles/75378/simple-yet-useful-tips-when-using-python) why?

## Replies

### Reply by Aryan Kumar

The **yield** keyword and the **return** keyword serve different purposes in Python, and they are used in different contexts.\
if you want to create a generator that produces a sequence of values, you need to use the **yield** keyword. If you use the **return** keyword instead, the function will return the value and terminate, and you will not be able to resume its execution to produce the remaining values.

### Reply by Krishnapriya Rajeev

The yield keyword is similar to the return statement in Python, where both return some sort of object or value to where the function was called.

The key differences between the both of them are:

| **yield** | **return** |
| --- | --- |
| It returns a generator object to where the function containing *yield* was called. | It returns a simple value (integer, string, float etc.) to where the function containing *return* was called. |
| It only pauses the execution of the function. | It terminates the execution of the function. |
| *Yield* statements are executed when the function’s execution is resumed. | *Return* statements are never executed. |


---

Original Source: https://www.mindstick.com/forum/157753/yield-does-not-work-but-return-does-in-python-why

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
