+ 2
What is difference between using return or print? Or can they kinda be used interchangeably?
4 Answers
+ 7
return means you got an value and you can assign to a variable or constant or just forget it
print means it will always print the result on the console(mostly use for debugging)
+ 4
Return obviously return some object (value, string, tuple ect.), which could be operated in the following code. Print just display some text on your screen. This helps you to see what happens "inside" your code.
+ 1
in simple terms return as the name suggests returns from certain scope to another previous scope. more like you call a function it goes to function body perform tasks in that scope and returns back to the scope where it was called. now print is simply used to print some results in the console
0
"return" is a keyword used to return execution back to the calling function, with or without a return value. "print" is a library function and not a keyword and is used to print out or display values and/or variables to some output window.