Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does return mean in Python? [closed]

Tags:

python

return

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?

like image 426
user3162541 Avatar asked May 23 '26 13:05

user3162541


1 Answers

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.

like image 180
aychedee Avatar answered May 26 '26 03:05

aychedee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!