0

PRINT OR RETURN?

What is the speciality with the Return Function? What is the difference between Print(x) and Return(x) When to use return and when to use print?

20th Sep 2019, 8:42 AM
Md khaled
Md khaled - avatar
4 ответов
+ 4
You can use print() anywhere in your program, it will just write something in the console. You can use return at the end of a function (def block) and it will determine the result of the function, and give back the flow of execution to the point where the function was called.
20th Sep 2019, 9:12 AM
Tibor Santa
Tibor Santa - avatar
+ 3
When we use return the control returns back to the calling function.
20th Sep 2019, 4:45 PM
Manoj
Manoj - avatar
+ 2
the added bonus of using return over print in a function/method is that you can use the value that is returned in a different way than just printing it. for example, if you have a function return a number/result of a calculation you can use that number/result in a different calculation. if the function just prints at the end you can’t use the value anywhere else. https://code.sololearn.com/chjFVpJz65xe/?ref=app
20th Sep 2019, 9:36 AM
Brave Tea
Brave Tea - avatar
+ 1
print() only prints out a value onto the screen return returns a value to be printed or used later on
20th Sep 2019, 8:47 AM
Trigger
Trigger - avatar