+ 1
Return function
I don't understand the difference between return and print, who can explain me ?
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
+ 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
+ 1
okay thank you very much :D
0
mhhh so return is for using this value ?