Question:medium

What does the return statement do in a function? Explain with the help of an example.

Show Hint

Use return to pass the result back
and continue using it elsewhere in your program.
Updated On: Jan 14, 2026
Show Solution

Solution and Explanation

The return statement in Python is utilized within functions to transmit a computed value back to the code that invoked the function. Execution of the return statement terminates the function's operation at that point, yielding the specified value. Absent a return statement, a function implicitly returns None. Example:
def add(a, b):
    result = a + b
    return result

sum = add(5, 3)
print(sum)
In the provided Example:, the add() function employs the return statement to output the sum of its parameters, a and b. This returned sum is subsequently assigned to the variable sum and then displayed.
Was this answer helpful?
0