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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With