Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

sdsasdv gdfgfdg
493 PointsExplain the concept of return to use in function?
Help me for why and when to use return.
3 Answers

Jennifer Nordell
Treehouse TeacherHi! I have a little analogy for you. Let's say I run a big business, but I'm really not good with bookkeeping. So I hand over all my receipts and invoices to my bookkeeper, and he/she is a wiz at doing this! Let's call this function balance_books
. They do a ton of complicated math and accounting that I have no idea about. But if they never return the results to me, it doesn't help me at all. I'm going to either need them to display the results themselves, or hand me back the results so that I can use them. So at the end of the balance_books
function (when the accountant is done), I add a return statement so that I can get back the results.
Hope this helps!

Steven Parker
242,796 PointsIt sounds like you have the basic idea.
But there's two basic kinds of functions:
- functions that do something
- functions that return something
And functions can be both at the same time. But functions that only "do" something might not have a return. And if they do have one, it would be to just end the function and not have a value with it. Whan a pure "do" function is called, it will usually be on a line by itself. Here's an example of a pure "do" function, it has no return:
def greet(who):
print("Welcome, " + who)
Functions that return a value will always have one (or more) return, and it will always have a value next to it. When a "return" function is called, it will typically be part of an assignment or an argument to another function. Here's an example of a "return" function:
def getName():
return input("What is your name? ")

Liam Clarke
19,938 PointsThe point of a function is to take an input and return something from that. So we use return statements in functions whenever we want that function to finish and return the value we needed.
so in Python we start a function with 'def' to give an input and end a function with 'return' when we have the functions output.
I hope i made this a little more clear for you, it can be confusing at first.

Jennifer Nordell
Treehouse TeacherHi Liam! I changed your comment to an answer to mark the question as answered on the forums and to allow for voting on your answer. Thanks for helping out in the community!