Don't understand what "return" is and what is going on here


I understand how if, elif, and else work, but I don't understand what "return" does, why there's a -1, and the numbers in parenthesis.

Replace this line with your code.


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

Consider the function below:

def correct(x):
    if x == 'yes':
        return True
        return False

I have multiple returns. So return doesn't just end a function definition. It is actually the point at which the function returns the result to the caller which would be a certain line inside of the function.


In these exercise, can you distinguish between "return" and "print"?

Why would we use one vs the other?


return is mainly used for functions and if/else statements and is highly recommended inside functions.
You cannot return the flow of control to a calling function with the print statement.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.