I really need someone to explain the return character in a function very simple and understandable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I really need someone to explain the return character in a function very simple and understandable

9th Nov 2020, 3:45 PM
Umar Amour Amidu Ndongo
Umar Amour Amidu Ndongo - avatar
2 Answers
+ 9
Oumar Amidu Ndongo , here is short sample with some comments: def add(num1, num2): sum_ = num1 + num2 return sum_ inp1 = 3 inp2 = 5 res = add(inp1, inp2) print(res) # or in short: print(add(inp1, inp2)) - you have 2 variables inp1 and inp 2, each of them holds an integer number - you also have a function add(), that can take 2 arguments - you call the function with add(inp1, inp2), so you pass the 2 arguments to this function. - the 2 values passed to the function are now in the variables num1 and num2 - the function adds the 2 numbers and stores the result in variable sum_ - last step in the function is to return the variable sum_ back to the caller and is stored there in a variable called res - finally the variable res will be printed and shows 8 as result.
9th Nov 2020, 4:21 PM
Lothar
Lothar - avatar
+ 1
Very simple: return returns what you posted after return, in... right side, ....of the return statement. --left side-- return --right side-- <=here Understandable: function can return something and can do not return. it depends have you placed return in function or not. def whoho(): return "spam and eggs" def hohoo(): print(spam eggs")
9th Nov 2020, 4:12 PM
Shadoff
Shadoff - avatar