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


#1



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.


#2

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
    else:
        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.


#3

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

Why would we use one vs the other?


#4

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.


#5

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