+ 1

Can some explain the return function?

i dont really understand what it means to return a value; I've reviewed it so many times but i just cant completely understand it. Can someone please explain it or dumb it down for me plz.

30th Apr 2018, 3:44 PM
M. Rosen
M. Rosen - avatar
3 ответов
+ 3
return uses in functions. e.g= def h(a,b): return a+b function give some value using return if you use return in your function then you can do some more with it. e.g= print(h(5,3)*2) #output=16 here you can see we don't multiply with 2 in function but we can also do more stuff with it when you call a function,remember that in print() statement this is opposite.
1st May 2018, 7:37 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
A function can return a value. This means anything that uses such function will get a value from it (number, text ect) which then that value can be used for other purposes. E.g. def add(a, b): return a + b # adds both parameters then returns the answer var = add(5, 2) # var’s value is now 7 because the function added 5 and 2 and returned the answer print(var) # proof print(add(5, 2)) # this would work too because the print function uses the value the add function returns
30th Apr 2018, 3:59 PM
TurtleShell
TurtleShell - avatar