# The Python Return Statement - A guide with examples

**URL:** <https://forum.freecodecamp.org/t/the-python-return-statement-a-guide-with-examples/19194>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [July 11, 2016, 2:39am UTC](https://forum.freecodecamp.org/t/the-python-return-statement-a-guide-with-examples/19194 "2016-07-11T02:39:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [July 11, 2016, 2:39am UTC](https://forum.freecodecamp.org/t/the-python-return-statement-a-guide-with-examples/19194/1 "2016-07-11T02:39:39Z")

</div>

All functions return a value when called.

If a return statement is followed by an expression list, that expression list is evaluated and the value is returned:

```auto
>>> def greater_than_1(n):
... return n > 1
...
>>> print(greater_than_1(1))
False
>>> print(greater_than_1(2))
True

```

If no expression list is specified, `None` is returned:

```auto
>>> def no_expression_list():
... return # No return expression list.
...
>>> print(no_expression_list())
None

```

If a return statement is reached during the execution of a function, the current function call is left at that point:

```auto
>>> def return_middle():
... a = 1
... return a
... a = 2 # This assignment is never reached.
...
>>> print(return_middle())
1

```

If there is no return statement the function returns None when it reaches the end:

```auto
>>> def no_return():
... pass # No return statement.
...
>>> print(no_return())
None
 

```

A single function can have multiple `return` statements. Execution of the function ends when one of these `return` statements is reached:

```auto
 >>> def multiple_returns(n):
 ... if(n):
 ... return "First Return Statement"
 ... else:
 ... return "Second Return Statement"
 ...
 >>> print(multiple_returns(True))
 First Return Statement
 >>> print(multiple_returns(False))
 Second Return Statement
 

```

A single function can return various types:

```auto
 >>> def various_return_types(n):
 ... if(n==1):
 ... return "Hello World." # Return a string
 ... elif(n==2):
 ... return 42 # Return a value
 ... else:
 ... return True # Return a boolean
 ... 
 >>> print(various_return_types(1))
 Hello World.
 >>> print(various_return_types(2))
 42
 >>> print(various_return_types(3))
 True

```

It is even possible to have a single function return multiple values with only a single return:

```auto
 >>> def return_two_values():
 ... a = 40
 ... b = 2
 ... return a,b
 ...
 >>> print("First value = %d, Second value = %d" %(return_two_values()))
 First value = 40, Second value = 2

```

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [August 7, 2017, 1:44am UTC](https://forum.freecodecamp.org/t/the-python-return-statement-a-guide-with-examples/19194/2 "2017-08-07T01:44:17Z")

</div>

Closed on August 7, 2017, 1:44am UTC


