+ 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.
3 Answers
+ 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.
+ 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