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