Return Statement

The return statement is one of the most important concepts in Python functions. It is used to send a value back from a function to the place where the function was called.

The return statement is a keyword used to send a result from a function back to the program.

Returned values can be:

  • stored in variables
  • reused later
  • used in calculations
  • used in decision-making statements

What is the Return Statement?

return statement is used inside a function to send a value back to the caller.

Once Python encounters a return statement:

  • the function stops executing
  • the value is sent back
  • control returns to the function call

Real-World Return Scenarios

  • Grading System: A function calculates your score and returns "Pass" or "Fail."

  • Shopping App: A function adds up the items in your cart and returns the total bill amount.

  • Login System: When you enter a password, a function returns True if it's correct.

  • Calculator: You send numbers to a function, and it returns the final answer.

Why Return Statement is Important

The return statement helps programmers:

  • Reuse values
  • Perform calculations
  • Build complex logic
  • Improve code efficiency
  • Create dynamic programs

Syntax

def function_name():
    return value


Example 1: The Math Result

def add(a, b):
    return a + b

# We save the result of the function in a variable
result = add(5, 3)
print(result)


Output

8


Example 2: Sending a Message Back

def message():
    return "Welcome"

print(message())


Output

Welcome

Real-Time Scenario

Calculator Application

When you press:

5 + 5

Function Returning Multiplication Result

def multiply(a, b):
    return a * b

result = multiply(10, 20)

print(result)

Output

200

the calculator does not simply print the answer.

It:

  • calculates the result
  • returns the value
  • displays it

This is exactly how Python functions work with return statements.

Difference Between print() and return

print() return
Displays output Sends value back
Mainly used for showing results Used for calculations and logic
Cannot easily reuse output Returned value can be reused
Output appears immediately Value can be stored in variables
Best for simple display Best for real-world applications 

Advantages of Return Statement

  • Returns results to the program
  • Allows value reuse
  • Supports calculations
  • Improves program flexibility
  • Useful in decision-making
  • Makes functions dynamic
  • Reduces code duplication

Common Beginners Mistakes

1. Using print() Instead of return

def add():
    print(10 + 20)

Cannot easily reuse the result.

2. Forgetting to Store Returned Value

def add():
    return 10 + 20

add()

The value is returned but not stored.

3. Writing Code After Return

def add():
    return 10
    print("Hello")

The print statement never executes.


Summary:

  • Instant Stop: Nothing written after the return line inside a function will ever run.

  • Smart Programs: Using return makes your functions much more powerful because they can "talk" to the rest of your code.

  • Calculations: Always use return when your function is doing math or making a decision.

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What does the return statement do in a function?

The return keyword is used to pass a result out of a function and end its execution.

Question 2

What happens to the code written inside a function after a return statement?

Return acts like an exit door; once the computer walks through it, the rest of the function code is skipped.

Question 3

What is the main difference between print() and return?

print() is for humans to see, while return is for the computer to use the data in other parts of the program.

Question 4

Look at this code:

 def check(): 
       return 10; 
print(20). 

What is printed?

The function returns 10 and stops before reaching print(20). To see the 10, you must print the function call.

Question 5

Can a Python function return more than one value at a time?

Python allows you to return multiple values (like return a, b), which actually creates a small tuple.

Congratulations!

You've successfully mastered the knowledge check for "Return Statement."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic Function Parameters Next Topic Projects