What does return mean in Python? [closed]

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.

Leave a Comment