Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Return Statement

Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Return Statement

return Statement in Python

In Python, the return statement is used inside a function to send back a value or result to the place where the function was called. Once the return statement runs, the function ends immediately, and the returned value can be stored, printed, or used in other operations.

Example: Returning a Full Name

Let’s create a function that builds a full name using three parts and returns it:

				
					def build_name(first, middle, last):
    return "Welcome, " + first + " " + middle + " " + last

greeting = build_name("Ahsan", "Raza", "Malik")
print(greeting)

				
			

Output:

				
					Welcome, Ahsan Raza Malik

				
			

In this example:

  • We call the function build_name() and pass three strings.

  • The function joins them into one message and sends it back using return.

  • That value is stored in the greeting variable and printed.

Why use return?

  • To send back a result for further use.

  • To exit the function early with a final value.

  • To avoid printing directly inside the function when reusability is needed.

Here’s another short example that shows how return can be used in a calculation:

				
					def square(num):
    return num * num

print("Square of 7 is:", square(7))

				
			

Output:

				
					Square of 7 is: 49

				
			

Summary

The return statement hands over the result from a function to the main code. It’s an essential part of building reusable and modular programs in Python

Scroll to Top