Point of "return"? Why not just print it?


#1

In the following code:

def hotel_cost(nights):
  return 140*nights

I don’t understand the point of return? Does it save it as a formula? As far as I know, the only way “return” differs from “print” is that it does not appear in the shell?

Thanks in advance for explaining to me in layman’s terms!


#2

return does literally what it says, handing you something back (in other words, return! )

the easiest way to demonstrate:

def hotel_cost(nights):
  return 140*nights

x = hotel_cost(3)
print x

we can capture the returned result in a variable named x, this can be very handy to do


#3

Thanks for your answer.
If I ELI5, is it correct to say that the return statement saves its data/code’s content so it can be used later?
Would you ELI5 it like that?


#4

what is ELI5 ?

no, return hands something back. What you do with this returned data, is up to you


#5

Explain/Elaborate Like I’m 5, it’s popular Reddit slang :grinning:


#6

You can’t expect everyone to know reddit slang, let alone me (non reddit and non native english speaker)

but no, your explanation isn’t quite good enough.