Skip to main content

Python Function: The return Statement

The return statement is the key component of the function. It is used to end the execution of the function call and “returns” the result (value of the expression following the return keyword) to the caller.  A return statement with no arguments is the same as return None.

Syntax:

def fun():
    statements
    .
    .
    return [expression]

Example: 

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

res = add(9,5)
print("Result =",res)

Output: Result = 14

It is even possible to have a single function return multiple values with only a single return.

Example:

def func():
    abc = "Hello"
    c = "Python"
    return abc,c;

abc, c = func()
print(abc)
print(c)

Output:

Hello
Python
Tags
Submitted by devanshi.srivastava on June 15, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.