What does return in Python mean?

I searched the entire internet for the meaning of instructions return.

I know this ends the define statement, but I know that it is still doing something else!

What else is he doing?

+3
source share
2 answers

This returnsis the control flow of the calling function. It also returnsoutputs / outputs to the calling function.

Consider the function below:

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

You have several returns. Thus, it returndoes not just end the function definition. Instead, this is the point at which the function returns the result to the caller.

If answer“yes”, then nothing after the if statement (after if and else) never starts because the function has already been returned.

+9

docs , . google python return...

+2

All Articles