+ 1

What is the difference between "print" and "return" in a function?

I really don't understand what's the difference, the output is always the same no matter what i use

16th Jul 2022, 6:55 PM
Lilly
Lilly - avatar
3 Answers
+ 4
return returns value to calling statement, used in function. print() just print text on the console output. edit: def func() : return "hello" r = func() # calling statement caches return value "hello" print( r ) # r using in printing. def func2() : print( "hello" ) # none returning func2() #calling function, none returns from function.
16th Jul 2022, 7:03 PM
Jayakrishna 🇼🇳
+ 2
Jayakrishna🇼🇳 already explained it good. I just give an example where return's of better usage. Task: You get two value and now calculate the sum of both values +1. def func(x): return x +1 print(func(5)+func(4)) Now for two values isn't that rly deficult but for more with user input would I rather do so. edit: sry when I Made something wrong don't use python.
16th Jul 2022, 7:50 PM
Felix Alcor
Felix Alcor - avatar