0

Need help Python3

Im confused By the keyword of "return" im confused for the last week after i studied about return and can anyone please tell me what does return do? *if indonesia is possible then explain in indonesia

31st Mar 2020, 9:54 AM
CutieRei
CutieRei - avatar
2 Réponses
+ 6
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))
31st Mar 2020, 10:49 AM
Lothar
Lothar - avatar
+ 1
owhh thanks so much!
31st Mar 2020, 2:26 PM
CutieRei
CutieRei - avatar