+ 4

Return vs Print in Python

How do i understand the difference between return and print statements in a python function?

3rd Mar 2017, 8:26 AM
Aakarsh Gupta
4 Answers
+ 9
Consider a function, add, it takes 2 parameter x and y. def add(x,y) return (x+y) This function will RETURN x+y Example if we use it, a=add(5,4) Here, x=5,y=4 and add will return 5+4 .Hence the value of a will be 9(BUT it will not be printed on screen unless you give print(a) command)
3rd Mar 2017, 8:44 AM
Meharban Singh
Meharban Singh - avatar
+ 1
Got it!! Thanks
3rd Mar 2017, 9:50 AM
Aakarsh Gupta
+ 1
thx helpful
4th Mar 2017, 1:32 AM
Abdullai Jafaru
Abdullai Jafaru - avatar
0
def add(x, y): colon is missing sir. we should include colon while defining a function.
2nd Apr 2019, 11:51 AM
Ram Kishore
Ram Kishore - avatar