+ 1

Return function

I don't understand the difference between return and print, who can explain me ?

30th May 2018, 1:02 PM
Marc Betous
Marc Betous - avatar
5 Respostas
+ 6
Think of a cash machine - print is when you ask it to show your balance (shows $200 or whatever). Return is like withdrawing $200, you have the value in your hand to use
30th May 2018, 1:21 PM
Dan Walker
Dan Walker - avatar
+ 1
That's right, so you can use this to assign to a variable. For example, our cash machine code could have a getBalance() method which will return a value, so we can write a = cashMachine.getBalance() and a will have the value returned by the method. In the early stages it can be hard to see the difference, because you rely on the output more often. With more complex programs with many steps you will need to pass data around and this will be the use of return. print is only useful for the programmer/user
30th May 2018, 1:43 PM
Dan Walker
Dan Walker - avatar
+ 1
okay thank you very much :D
30th May 2018, 1:44 PM
Marc Betous
Marc Betous - avatar
0
mhhh so return is for using this value ?
30th May 2018, 1:39 PM
Marc Betous
Marc Betous - avatar