0

What is difference between Print () and return ??

Explain with example if possible.

28th Apr 2020, 7:09 AM
Harish Gajjar
Harish Gajjar - avatar
2 Respostas
+ 1
"print" always output its unamed arguments to the standard output (console/terminal -- unless you explicitly set specific behavior through named specific parameter ^^) and as a function, have None return value (in python prior to 3 "print" was a statement). "return" is a keyword statement used to return a value from a function: def spam(): return "egg" var r = spam() print(r) # output: egg What should be confusing to you, is the behavior of the python command line interpreter (when you doesn't run a script file directly, but run python itself, and get the ">>>" prompt for typing python instructions wich will be executed as soon as you validate your entry: >>> print("egg") egg >>> def spam(): . . . return "egg" . . . >>> spam() egg Why that seems doing the same thing? Because in these context, an implicit print() is done with the result of the instruction entered: >>> "e"+"g"+"g" egg >>> s = "egg" # no output as an assignation return None (as a function without return statement) >>> s egg
28th Apr 2020, 10:27 AM
visph
visph - avatar
0
return is used inside a function so whenever you call that function it returns the value written with "return" in function. whereas Print can be used inside or outside a function.(Some languages like python ,Jscript. etc doesn't need a function to run simple codes. But C,C# etc does )
28th Apr 2020, 8:01 AM
Noman S. Shiekh
Noman S. Shiekh - avatar