Return and print | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Return and print

Can anyone explain to me in a simple way on the difference of return and print?, Like the use of it.

29th Aug 2021, 5:50 AM
Ervan
Ervan - avatar
9 Answers
+ 5
Hi Ervan! We believe the same thing was discussed in many times here too. I could find something from the Internet. It's really cool explanation https://stackoverflow.com/questions/7664779/what-is-the-formal-difference-between-print-and-return
29th Aug 2021, 5:57 AM
Python Learner
Python Learner - avatar
+ 5
Ervan return is just return value in function but can't print anything on terminal. print function in used to print results on terminal. return is used in function to return value back to the function. You can print this return value either directly calling function or you can assign returned value to a variable then print that variable. def returnExample(): a = 10 b = 20 return a + b #---------- print (returnExample ()) #---------- result = returnExample () print (result)
29th Aug 2021, 8:38 AM
A͢J
A͢J - avatar
+ 3
Print will send whatever is inside the ‘( )’ to the console. That way you can see it. Return, well, thats a little complicated. It give back a value. For example, if you have a function: // BigNumberIs( X, Y ): Return Answer // #Now what it does is return the number that’s bigger. So BigNumberIs(6, 7) will be 7. But you wont see that number. It wont be printed. Its just for the computer to use. It just replaces the function with the answer. 12 x BiggerNumberIs(7, 8) ==> 12 x 8 ==> 96 /// Just like that: print(BiggerNumberIs(4,9)) ==> print(9) ///==> 9 <==\\\
29th Aug 2021, 7:44 AM
Samanth Martis
Samanth Martis - avatar
29th Aug 2021, 6:04 AM
<★Shaurya Chauhan★>(ACTIVE AGAIN✌😇🙃)
<★Shaurya Chauhan★>(ACTIVE AGAIN✌😇🙃) - avatar
+ 1
print prints the value to the console, return gives back a value from a function or method. So the value from print is the output, return is a value you can use for further computation
29th Aug 2021, 6:16 AM
Knäcke Brot
Knäcke Brot - avatar
+ 1
In python, print is a function that accepts many arguments then writes them on the stdout (console), However, return is a keyword used in a function to return some value when being called NOTE: when using return keyword in a function it returns some value and stops the process of that func. Syntax: #print print("hello", "world") #prints hello world #return def greet(): return "hello world" greet() #it returns "hello world" print(greet()) #print the value returned by greet function
29th Aug 2021, 10:06 AM
Sousou
Sousou - avatar
0
Return is used in function to return the value on calling the function Def sum () : Return 5+6 A = sum() A will be 11 Print is used to print anything on terminal
31st Aug 2021, 4:23 AM
Utkarsh Gautam