2 AnswersNew Answer
Here are 2 samples with return, and a short explanation. You have a "main" program with 2 variables, that should be added and then print the result. The addition will be done by a function called "add". By calling the function, the values of the the 2 variables are passed to the function. The function does the calculation, and then returns this calculated value back to the calling part of the program. The returned value can be stored in a variable and then printed. As soon as "return" is executed and has returned the sesult, the control flow will leave the function and is going back to the "main" program. # sample with return detailled def add(num1, num2): sum_ = num1 + num2 return sum_ # "main" program a = 7 b = 15 res = add(a,b) print(res) # sample with return short def add(num1, num2): return num1 + num2 a = 7 b = 15 print(add(a,b))
owhh thanks so much!