Hi guys... what's deferent between (print and return) in function | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Hi guys... what's deferent between (print and return) in function

function in python

12th Jan 2017, 3:51 PM
Hary Doski
Hary Doski - avatar
2 Antworten
+ 4
I don't know python, but you can probably understand it in the context of JavaScript. This is print, function myFunc() { document.write("Hello") } // document.write() is equivalent to print, which obviously prints something to the screen This is return, function myFunc() { return "Hello" } ; document.write(myFunc()) See the difference?
12th Jan 2017, 4:09 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
0
In tutorials and examples, it is difficult to see much of a different. However, when writing code to do something useful, the difference becomes more obvious. Print is typically used to show the user some feedback on what the program is doing but return is used by functions to provide a result to the caller. The caller can then decide what to do with the return'd value. They can print the value, modify it, or react to it however they deem appropriate. When something is printed, the code calling the function does not have access to that value.
12th Jan 2017, 5:28 PM
Nathan
Nathan - avatar