Python Functions: Medical Insurance project - What's the point in the "return" statement?

Can you paste your formatted code so we can see?

The return statement does just that–when the function is called it returns a value or an object to the caller. The return does not work outside the function.


def cat(name): #defining the function with one parameter
    return "This is my cat, " + name  #returning this when the function is called

cat("Bea")   #calling the function, passing the argument

>>This is my cat, Bea

If you try to use the return statement outside the function, it won’t work/you’ll get an error:

return "This is my cat " + name

>>File "<ipython-input-3-dc74106e388c>", line 1
    return "This is my cat " + name
SyntaxError: 'return' outside function

Print gives a value to the user as some output, whereas return, returns an object to the program when you call the function.

Additionally, if you haven’t already, you could also do some basic research on what a return does as well. It’s in the docs, etc.