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?
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.
+ 3
When we use return the control returns back to the calling function.
+ 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
+ 1
print() only prints out a value onto the screen
return returns a value to be printed or used later on