forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 2
Python Functions Statements Return
Quincy Larson edited this page Aug 20, 2016
·
1 revision
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:
>>> 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:
>>> 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:
>>> 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:
>>> def no_return():
... pass # No return statement.
...
>>> print(no_return())
None
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links