Skip to content
Question 29 of 97

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

Rajasthan RbseCBSE Class XII Board 2025Subjective· 2mImportance★★★★★
30% · 29/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

The return statement sends a value back from a function to the caller and immediately exits the function. Without it, a function returns None by default.

The Core Idea

Think of a function like a vending machine. You put in money (arguments), press a button (call the function), and the machine gives you a product (the return value). The return statement is the mechanism that actually hands you that product. Without it, the machine might do work inside — lights flash, gears turn — but nothing comes out for you to hold.

In programming, when you call a function, you usually want it to compute something and give you the result. The return statement does two things at once:

  1. It sends a value back to the place where the function was called.
  2. It immediately stops the function — no further code in the function runs after return.

If a function has no return statement, Python still returns something: the special value None. This is like the vending machine saying "here's nothing" — technically a response, but not useful.

Step-by-Step Explanation

  1. What return does in a function

    When Python encounters return inside a function, it evaluates the expression after return (if any), then hands that value back to the caller. The function's execution ends right there — any lines after return are ignored.

  2. The default return value

    If a function ends without hitting a return statement, Python automatically returns None. This is a common source of bugs for beginners: they write a function that prints a result but forget to return it, then wonder why the variable they assigned gets None.

  3. Example: A function that returns a value

    Consider a function that calculates the area of a rectangle:

    def rectangle_area(length, breadth):
        area = length * breadth
        return area
    

    When you call result = rectangle_area(5, 3), the function computes 15, and return sends that 15 back. Now result holds 15. You can use it in further calculations.

  4. Example: A function without return

    Compare with this version:

    def rectangle_area(length, breadth):
        area = length * breadth
        print(area)
    

    Calling result = rectangle_area(5, 3) prints 15 to the screen, but result becomes None. The function did the work but didn't hand back the value — it only showed it. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.