# Return Keyword in Python Functions

**URL:** <https://discuss.python.org/t/return-keyword-in-python-functions/33791>\
**Category:** Python Help\
**Created:** [September 15, 2023, 6:39am UTC](https://discuss.python.org/t/return-keyword-in-python-functions/33791 "2023-09-15T06:39:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moonlight001](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@Moonlight001](https://discuss.python.org/u/Moonlight001)\
**Post date:** [September 15, 2023, 6:39am UTC](https://discuss.python.org/t/return-keyword-in-python-functions/33791/1 "2023-09-15T06:39:59Z")

</div>

Why is “return 123” ignored in this case?

```auto
def boring_function():
    print("'Boredom Mode' ON.")
    return 123

print("This lesson is interesting!")
boring_function()
print("This lesson is boring...")

```

This lesson is interesting!  
‘Boredom Mode’ ON.  
This lesson is boring…

And, why is the whole function ignored in this another case:

```auto
def boring_function():
    return 123
    print("'Boredom Mode' ON.")
    

print("This lesson is interesting!")
boring_function()
print("This lesson is boring...")

```

This lesson is interesting!  
This lesson is boring…

Thank you.

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [September 15, 2023, 7:02am UTC](https://discuss.python.org/t/return-keyword-in-python-functions/33791/2 "2023-09-15T07:02:16Z")

</div>

Because you do not do anything with the result of the function.

You could print the result like this:

```auto
print("This lesson is interesting!")
print(‘function returned’, boring_function())
print("This lesson is boring...")

```

---

<div class="post-metadata">

**Author:** ![Moonlight001](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@Moonlight001](https://discuss.python.org/u/Moonlight001)\
**Post date:** [September 15, 2023, 7:20am UTC](https://discuss.python.org/t/return-keyword-in-python-functions/33791/3 "2023-09-15T07:20:11Z")

</div>

Okay. I see. Thank you.

I have a follow up question… In this case, why is the print line ignored, even though it has the word “print”?

```auto
def boring_function():
    return 123
    print("'Boredom Mode' ON.")
    
boring_function()

```

123

Thanks.

---

<div class="post-metadata">

**Author:** ![aivarpaalberg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aivarpaalberg/32/9457_2.png) [@aivarpaalberg](https://discuss.python.org/u/aivarpaalberg)\
**Post date:** [September 15, 2023, 7:32am UTC](https://discuss.python.org/t/return-keyword-in-python-functions/33791/4 "2023-09-15T07:32:25Z")

</div>

From documentation: [The `return` statement](https://docs.python.org/3/reference/simple_stmts.html#the-return-statement)

> [`return`](https://docs.python.org/3/reference/simple_stmts.html#return) leaves the current function call with the expression list (or `None` ) as return value.

So anything in function body what is after return is not executed.

---

<div class="post-metadata">

**Author:** ![Moonlight001](https://avatars.discourse-cdn.com/v4/letter/m/d78d45/32.png) [@Moonlight001](https://discuss.python.org/u/Moonlight001)\
**Post date:** [September 15, 2023, 7:46am UTC](https://discuss.python.org/t/return-keyword-in-python-functions/33791/5 "2023-09-15T07:46:19Z")

</div>

I see. Thank you!

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [September 15, 2023, 10:49pm UTC](https://discuss.python.org/t/return-keyword-in-python-functions/33791/6 "2023-09-15T22:49:20Z")

</div>

`print` and `return` have **nothing to do with each other**.

The purpose of `print` is to _send text to the terminal_, which will display it. (You can also tell it to “print” into a file.) It’s important to understand here that **Python does not display your text** - the terminal does, and it’s responsible for understanding any “special” characters like newline (to move the output onto the next line), tab (to advance to a specific position), etc. as well as for figuring out what font to use. The terminal is a very basic program that will use the same font and size for all the text that it shows. Some terminals can understand special codes that control the text colour, a few basic effects like boldface and underline, and “moving to” a position to display the next part of the text. But it will always use the same font for everything, which is controlled by the end user (configuration settings for the terminal window) and not by your program, and that font will pretty much always be a monospace (“typewriter”) font.

The purpose of a function is to _compute a result_, and the purpose of a function is to _report_ that result back to the caller - which can then do _anything it likes_ with that result. It is exactly like how using `+` to add two numbers gives a result that the caller can use for any purpose. It _doesn’t make anything show up on the screen_.

**Specifically when you use the Python interpreter prompt (“REPL”)**, it will automatically display (in more or less the same way as `print` does) a _string representation of_ the result from each statement that you type in, one at a time, **if**

- the statement _has_ a result (it’s an _expression_, basically meaning that you could put `a = ` on the left-hand side of it and still have valid syntax) **and**
- the result is _not_ the special value `None`.

When you call `print` in the REPL, for example, you are _using a function_ that will display some text _as a side effect_, and then `return None`. The REPL will see that the result was `None`, so it doesn’t also display that.
