How to return a function as a return value in Python

Python return statement:

A return statement 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. The statements after the return statement is without any expression, then the special value None is returned. A return statement is overall used to invoke a function so that the passed statements can be executed.

Note: Return statement can not be used outside the function.

Syntax: 

def fun():

      statements

      .

      .

      return [expression]

Example:
def add(a, b):
    return a + b
def is_true(a):
    return bool(a)
res = add(2, 3)
print("Result of add function is {}".format(res))
res = is_true(2<5)
print("\nResult of is_true function is {}".format(res))

Output:

Result of add function is 5
Result of is_true function is True

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top