3
votes

I searched the whole internet for the meaning of the return statement.

I know it ends the define statement, but I know it still does something else!

What else does it do?

2
This question appears to be off-topic because the answer is easily found by googling "return python" - thefourtheye
In Python 2, return returns a value from a function. That's all it does. In Python 3, it can also return values from generators. - Blender
It means the same thing it means in all other programming languages that have a return statement. This is not at all specific to python; and is also covered in just about every introductory programming tutorial that deals with functions. - l4mpi

2 Answers

9
votes

It returns the flow of control to the calling function. It also returns output/results to the calling function.

Consider the function below:

def am_i_wrong(answer):
    if answer == 'yes':
        return True
    else:
        return False

You have multiple returns. So return doesn't simply end the function definition. It instead is the point at which the function returns the result to the caller.

If answer is equal to 'yes' then anything after the if statement (after if and else) is never run because the function has already returned.

2
votes

The docs explain fully how a return function works. Its also the first answer in the google query python return...