0

Why we use return in function ?

30th Jul 2025, 5:50 AM
Amritpal Singh
Amritpal Singh - avatar
2 Réponses
+ 3
Return can be written as the result of a function in any variable when the function is called. For example: def calculate(x, y): return x+y sum = calculate(3, 7) print(sum) This will print 10. You can repeat this with other variables. sum2 = calculate(10, 5) print(sum2) This will print 15.
30th Jul 2025, 7:00 AM
Mila
Mila - avatar
0
Amritpal Singh , functions can be made to do operations and output a result when they are called. in other cases we do not need to output the result from the function itself, but we may work with it in our main program. > functions perform operations. > if we need to use values in the calling programm, we can return them. > they can be assigned to a variable and can be used for further purpose. find some more details in the attached file: https://sololearn.com/compiler-playground/c8g4iFWcy976/?ref=app
30th Jul 2025, 9:41 AM
Lothar
Lothar - avatar